In this example we show how to work with JDOM parser to parse the xml document. JDOM can read existing XML documents from files, network sockets, strings, or from reader. JDOM does not has its own native parser. XML parsing produces an xml parse tree from an XML document. Using the JDOM packages, it's very simple to work with parsed XML documents.
Working with XML document, use the following from JDOM package:
1. Simply make an object of org.jdom.input.SAXBuilder with no-args
constructor
2. Call the Builder's build() method to build a document object from a
reader, InputStream, URL, File or a String containing a system ID.
3. Navigate the document using the methods of the document class, the Element
class, and the other JDOM classes.
For Example:
| SAXBuilder saxBuilder = new SAXBuilder();
Document doc = saxBuilder.build("http://localhost:8080/ |
The following example file 'JDOMparsingxml.jsp' will show you the use of JDOM parser to parse the 'roseindia.xml' file and display it to the page.
JDOMparsingxml.jsp
<%@ page import= "org.jdom.*, java.util.*,
|
roseindia.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
|
Run the program on this url: http://localhost:8080/ServletExample/jsp/JDOMparsingxml.jsp and following output will be displayed

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Parsing The XML File Using JDOM Parser in JSP View All Comments
Post your Comment