Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It really depends on what you want to do with the XML document and how big the documents are.</p> <p>Roughly, you can categorise XML APIs as:</p> <ul> <li><strong>DOM APIs</strong> - load the entire document into memory, which limits the size of document you can process, but can then create optimised structures for navigation and transformation</li> <li><strong>Streaming APIs</strong> - your application must interpret low level parse events (e.g. start of element, end of element, etc.) but you are not limited by memory. There are two kinds of streaming API - push and pull. Push parsers fire parse events at an object you define and that object must keep track of the current parse state, with a state machine or stack, for example). Pull parsers let your app pull parse events from the parser. This makes it easy to write a recursive descent parser to process the XML content, but then stack size becomes a limit on the size of document you can process.</li> <li><strong>XML Mappers</strong> - map XML content to Java objects. There are two main approaches for XML mapping: code-gen or reflection. Code-gen mappers generate Java classes from an XML schema, which means you don't have to duplicate the schema structure in Java code but does have the disadvantage that your Java code exactly mirrors the schema structure. Also most code generators create <a href="http://puttingtheteaintoteam.blogspot.com/2008/10/is-that-pojo-or-nojo.html" rel="nofollow noreferrer">NOJO</a> classes that are awkward to work with and have no behaviour of their own. Reflective mappers let you to write Java classes with rich behaviour and then define how they are mapped to/from XML. If you need to conform to a predefined schema, you'll have to make sure your classes and mapping configuration are correct w.r.t. that schema. </li> </ul> <p>Some options available are:</p> <ul> <li>DOM APIs: The DOM APIs in the standard library are standard (obviously!) and so interoperate with other libraries but they are awful. There are several more convenient DOM-like APIs, such as <a href="http://www.xom.nu/" rel="nofollow noreferrer">XOM</a> (my favourite for the same reasons that Adam Batkin gives above) or <a href="http://www.jdom.org/" rel="nofollow noreferrer">JDOM</a>. Have a look at a few and decide which API you prefer.</li> <li>Streaming APIs: the standard library contains an implementation of the SAX push parser. The standard pull parser for Java is <a href="http://stax.codehaus.org/Home" rel="nofollow noreferrer">StAX</a>.</li> <li>Mapping APIs: <a href="http://jaxb.java.net/" rel="nofollow noreferrer">JAXB</a> is a JSR standard but I prefer <a href="http://xstream.codehaus.org" rel="nofollow noreferrer">XStream</a> because I can more easily separate the mapping configuration from the mapped classes (no need for annotations or XML configuration) and it maps objects to/from other data formats.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload