
- Java XML Home
- Java XML Overview
- Java XML Parsers
- Java DOM Parser
- Java DOM Parser
- Parse XML Document
- Query XML Document
- Create XML Document
- Modify XML Document
- Java SAX Parser
- Java SAX Parser
- Parse XML Document
- Query XML Document
- Create XML Document
- Modify XML Document
- JDOM XML Parser
- JDOM XML Parser
- Parse XML Document
- Query XML Document
- Create XML Document
- Modify XML Document
- Java StAX Parser
- Java StAX Parser
- Parse XML Document
- Query XML Document
- Create XML Document
- Modify XML Document
- Java XPath Parser
- Java XPath Parser
- Parse XML Document
- Query XML Document
- Create XML Document
- Modify XML Document
- Java DOM4J Parser
- Java DOM4J Parser
- Parse XML Document
- Query XML Document
- Create XML Document
- Modify XML Document
- Java XML Useful Resources
- Java XML - Questions and Answers
- Java XML - Quick Guide
- Java XML - Useful Resources
- Java XML - Discussion
Java JDOM Document getNamespacesInherited() Method
The Java JDOM getNamespacesInherited() method of Document class is used to get all the namespaces that are inherited by the current XML document at the document level.
Syntax
Following is the syntax of the Java JDOM Document getNamespacesInherited() method −
Document.getNamespacesInScope();
Parameters
The Java getNamespacesInherited() method doesn't accept any parameters.
Return Value
The Java getNamespacesInherited() method returns the list of inherited Namespace objects.
Example
Following is the books.xml file we need to parse −
<?xml version="1.0" encoding="UTF-16" ?> <book xmlns="http://domain/book"> <pre:name xmlns:pre="http://domain/bookName"> War and Peace </pre:name> </book>
The getNamespacesInherited() method returns an empty list when there are no namespaces inherited by the XML document.
import java.io.File; import org.jdom2.Document; import org.jdom2.input.SAXBuilder; public class NamespacesInherited { public static void main(String args[]) { try { //Reading the XML file SAXBuilder saxBuilder = new SAXBuilder(); File inputFile = new File("books.xml"); Document doc = saxBuilder.build(inputFile); System.out.println(doc.getNamespacesInherited()); } catch (Exception e) { e.printStackTrace(); } } }
The output window displays an empty list.
[]
Advertisements