Different types of XML Parsing in Java

SAX Parser (Simple API for XML):
SAX Parser reads one node at a time, it is very memory-efficient and fast.
While processing the XML the SAXParser calls the methods in  DefaultHandler instance corresponding to what the parser finds in the XML file.
It is the responsibility of the DefaultHandler subclass to extract any necessary information from the XML via these methods.

See following SAX callback methods :
   
 startElement() – triggers this event when the start of the tag is encountered.
 endElement() – triggers this event when the end of the tag is encountered.
 characters() – triggers this event when it encounters some text data.



DOM Parser (Document Object Model):
DOM Parser reads the whole XML document into memory, so the DOM API is not suitable for projects with very large XML files.
More importantly, it is somewhat more complex than the simplistic SAX method even for small and simple problems.

JAXB(Java architecture for XML binding):
JAXB mostly is used while implementing webservices
There are two operations you can perform using JAXB

   - Marshalling :Converting a java object to XML
   - UnMarshalling :Converting a XML to java object.

JAXB is high layer API so it has less control on parsing than SAX or DOM.
It has some overhead tasks so it is slower than SAX.


No comments:

Post a Comment