I am producing some XML in a java application. I am looking at the variety of XML parsing options. I am not intending to do anything more than traverse the structure and extract values out of it. I need to use one of them that is built into the Java API (1.5+) without any additional plugins. I don't need to create "events" or transform it into anything else. I am not producing XML, merely reading and extracting data. I am not enforcing a schema either.
Sun provide a list here, but it's not really obvious what I should use.
http://java.sun.com/developer/technicalArticles/xml/JavaTechandXML/
What would be the most appropriate XML API to use in this case ? JAXP ? JDom ? XPath ?
I think using a DOM parser to parse the XML and load it into memory in a Document sounds sufficient for your needs.
You wouldn't use XPath in that case, just the Document API.
JAXP is just a synonym for the XML parsing technology build into the JDK. The term JAXP (P is for Parsing) distinguishes it from JAXB (B is for binding).
Some 3rd party libraries built on top of DOM might make your life easier. Think about JDOM or DOM4J.
The most classical way of doing things in IMO would be combination of JAXP and XPath. Java 5.0 includes JAXP 1.3 and this is standard stuff. Please see this answer to a similar question for a minimalist coding sample.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With