XML Parser
XML Parser provides way
how to access or modify data present in an XML document. Java provides multiple
options to parse XML document.
1) Dom Parser -
DOM parser parses the entire XML document and loads it into memory; then models
it in a “TREE” structure for easy traversal and we iterate through the Node and Node List to
get the content of the XML. DOM Parser is slow and consumes a lot of
memory when it loads an XML document which contains a lot of data
2) SAX
Parser - SAX parser doesn’t load the complete XML into the memory,
instead it parses the XML line by line triggering different events as and when
it encounters different elements like: opening tag, closing tag, character data
and comments and so on. This is the reason why SAX Parser is called an event
based parser.
3) StAX Parser - StAX stands for Streaming API for XML. The SAX Parser pushes the data but StAX parser pulls the required data from the XML. StAX is a "pull" API. SAX is a "push" API.
StAX can do both XML
reading and writing. SAX can only do XML reading.
No comments:
Post a Comment