Thursday, October 15, 2015

DOM VS. SAX For XML Parsing

DOM (Document Object Model)
  • DOM Parser for Java is in JAXP (Java API for XML Parsing) package.
  • It represent an XML Document into tree format.
  • DOM Parser creates an In Memory tree representation of XML file and then parses it, so it requires more memory

SAX ( Simple API for XML Parsing)
  • It’s recommended to use SAX XML parser for parsing large xml files in Java because it doesn't require to load whole XML file in Java and it can read a big XML file in small parts.
  • SAX is an event based XML Parsing and it parse XML file step by step so much suitable for large XML Files.
  • SAX XML Parser fires event when it encountered opening tag, element or attribute and the parsing works accordingly. 
DOM VS. SAX 
  • DOM and SAX parser are extensively used to read and parse XML file in java
  • I recommend use DOM parser over SAX parser if XML file is small enough and go with SAX parser if you don’t know size of xml files to be processed or they are large.
  • SAX is an event based parser and raise and event, while DOM is not . 
  • At DOM Traverse in any direction.
  • At SAX Top to bottom traversing.
  • SAX is read only , DOM is read and write both. 
Read more:
http://javarevisited.blogspot.com/2011/12/difference-between-dom-and-sax-parsers.html#ixzz2WfmBqdl9


No comments:

Post a Comment

java - fill distinct objects in ArrayList

If you have a list that contains some objects that it is considered as duplication when two or three fields of these objects are equal. How ...