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.
|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.
Run the program on this url: http://localhost:8080/ServletExample/jsp/JDOMparsingxml.jsp and following output will be displayed
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: August 1, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles