Difference between SAX and DOM Parser is very popular Java interview and often asked when interviewed on Java and XML. Both DOM and SAX parser are extensively used to read and parse XML file in java and have there own set of advantage and disadvantage which we will cover in this article. Though there is another way of reading xml file using xpath in Java which is more selective approach like SQL statements people tend to stick with XML parsers. DOM Parser vs SAX parsers are also often viewed in terms of speed, memory consumption and there ability to process large xml files.
Difference between DOM and SAX XML Parser in Java
DOM XML Parser in Java
DOM Stands for Document Object Model and it represent an XML Document into tree format which each element representing tree branches. DOM Parser creates an In Memory tree representation of XML file and then parses it, so it requires more memory and its advisable to have increased heap size for DOM parser in order to avoid Java.lang.OutOfMemoryError:java heap space . Parsing XML file using DOM parser is quite fast if XML file is small but if you try to read a large XML file using DOM parser there is more chances that it will take a long time or even may not be able to load it completely simply because it requires lot of memory to create XML Dom Tree. Java provides support DOM Parsing and you can parse XML files in Java using DOM parser. DOM classes are in w3c.dom package while DOM Parser for Java is in JAXP (Java API for XML Parsing) package.
SAX XML Parser in Java
Difference between DOM and SAX XML Parser
Difference between SynchronizedCollection and ConcurrentCollection in Java
Difference between ArrayList and Vector in Java
Difference between Comparator and Comparable in Java
Difference between SendRedirect and Forward in Servlet and JSP
Difference between ClassNotFoundException and NoClassDefFoundError in Java
Top 10 Collection Interview Questions in Java
Difference between HashMap and HashSet in Java
No comments:
Post a Comment