Here are the different types of XML Processors in Java. Typically, they break down into 3 categories:
- Tree Based API's
- Streaming API's
- Binding-style API's
A Tree-based XML processor represents the entire XML document as a tree of objects in memory which gives a lot of convenience. The tree can be traversed forward or backward, inspect one part of the tree and then jump to another part of the tree easily.
The main advantage with tree based processor is that the user can search the XML content with XPATH expression language or with tools that are specific to a particular API. But, the downside of tree-based processor is that it takes more memory and certain tasks can be a lot slower than streaming API.
Eg: DOM, JDOM
Streaming Processors are designed to build or parse XML one node at a time. There are two kinds of streaming processors known as "
pull" and "
push" processors.
Eg: Simple API for XML(
SAX
) is a streaming processor. That means it pushes the data into call back methods that are designed. In contrast, this Streaming API for XML(
StAX
) is a pull process where only data is looked and only call methods that are meaningful.
Typically, pull processors are more convenient programming model but both types of streaming processors can be incredibly fast and highly-memory efficient. The downside of the streaming porcessor is that the complete dataset is not stored in memory at once. XPath style search is not applicable and also coating can be complex. Especially for SAX.
Binding Processors are similar to DOM in the background i.e. their tree style processors that store all the data in the memory all at the same time. But, the programming model is dramatically different to use. A binding processor like JAXB or Simple XML Serialization framework annotates the Java classes indicating which properties or fields have that class are mapped to the portions of XML structure and then runs the very simple code either serialize of deserialize the XML content.
The upside of binding processor is that it is very efficient programming model and is very easy to maintain and the downside is that the JAXB processor is included with Oracle's JDK is not available in Android. But, there is a binding processor that works with the android called as Simple XML Serialization Framewrok.
Eg: JAXB, Simple XML Serialization framework