
- 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 getBaseURI() Method
The Java JDOM getBaseURI() method of Document class is used to get the URI from which the XML document gets loaded. If the fetch location of the document is unknown, it returns null.
Syntax
Following is the syntax of the Java JDOM Document getBaseURI() method −
Document.getBaseURI();
Parameters
The Java getBaseURI() method doesn't accept any parameters.
Return Value
The Java getBaseURI() method returns a String value that represents the BaseURI.
Example 1
The following basic example uses the Java JDOM Document getBaseURI() method to get the file location.
import java.io.File; import org.jdom2.Document; import org.jdom2.input.SAXBuilder; public class GetBaseURI { public static void main(String args[]) { try { //Reading the document SAXBuilder saxBuilder = new SAXBuilder(); File inputFile = new File("D://cars.xml"); Document doc = saxBuilder.build(inputFile); //Get BaseURI String baseURI = doc.getBaseURI(); System.out.println("BaseURI : "+baseURI); } catch (Exception e) { e.printStackTrace(); } } }
The output window displays the BaseURI of the XML document.
BaseURI : file:/D:/cars.xml
Example 2
The getBaseURI() method returns null if the file location is unknown. The following java program illustrates this scenario.
import org.jdom2.Document; public class GetBaseURI { public static void main(String args[]) { try { //Creating new Document Document doc = new Document(); //Get BaseURI String baseURI = doc.getBaseURI(); System.out.println("BaseURI : "+baseURI); } catch (Exception e) { e.printStackTrace(); } } }
The output window displays null.
BaseURI : null
Advertisements