Whether one chooses JAXP (Java API for XML) or JAXB (Java API for XMLBinding) depends on the requirements of the application.
If one needs only a part of data then one should use the SAX parser because it parses data based on events and is really fast.
On the other hand is the document is not too large and nodes have to be inserted or removed then one should go for a DOM parser which allows the manupulation of the in memory XML file by allowing additions and deletion of nodes from this tree.
If the requirement is to transform the XML document from one format to another then the best choice is JAXP because it has a built in XSLT transformer that allows one to transform XML documents, SAX events and even a DOM tree.
If the document is too large for DOM to handle and also one needs an object reprentation of the XML data then you should use the JAXBAPI. However classes in JAXB do not allow tree manipulation capability and thus they occupy lesser memory footprint.
Another important advantageof JAXB over JAXP is that JAXB makes it mandatory for an XML document to have a DTD which is not necessary in case of JAXP. This ensures that the XML documents that are being parsed are valid documents.
JAXB also allows one to specify how the code is generated from the DTD including the data types that an element binding will accept and return.
However JAXB does not have any capability to transform an XML document into different formats which is available in the JAXP API's.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.