JAXP/XPath example - II
28 June 2008Continued from the last post. I will show how to parse a document using JAXP.
I will present an example that will search a XML file and then prints out the titles of all the books it finds.
First step is to load the document into a DOM Document object. I will use books.xml file in the example and it is assumed that it resides in the current directory:
Here’s a simple code fragment that parses the document and constructs the corresponding Document object:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); // never forget this! DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse("books.xml");
continued …
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: JAXP/XPath example - II