{"id":1774,"date":"2011-03-22T17:07:04","date_gmt":"2011-03-22T11:37:04","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1774"},"modified":"2011-03-22T17:07:04","modified_gmt":"2011-03-22T11:37:04","slug":"difference-between-sax-and-dom-parsers","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/difference-between-sax-and-dom-parsers\/","title":{"rendered":"Difference between SAX and DOM Parsers"},"content":{"rendered":"<p>In Previous articles we have discussed about JAXP in detail.<\/p>\n<ul>\n<li><a title=\"Introduction to DOM\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/dom-%e2%80%93-document-object-module\/\" target=\"_blank\">Introduction to DOM<\/a><\/li>\n<li><a title=\"Introduction to JAXP\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/introduction-to-jaxp\/\" target=\"_blank\">Introduction to JAXP<\/a><\/li>\n<li><a title=\"Create XML File\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/create-xml-file-using-jaxp-and-transformation-apis\/\" target=\"_blank\">Create XML File using DOM Parser of JAXP and Transformation APIs<\/a><\/li>\n<li><a title=\"Traverse XML File\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/traverse-xml-file-using-dom-parser-of-jaxp\/\" target=\"_blank\">Traverse XML file using DOM Parser of JAXP<\/a><\/li>\n<li><a title=\"Search XML File\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/searching-xml-file-using-dom-parser-of-jaxp\/\" target=\"_blank\">Searching XML File using DOM Parser of JAXP<\/a><\/li>\n<li><a title=\"Read XML File using SAX Parser\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/read-xml-file-using-sax-parser-in-java\/\" target=\"_blank\">Read XML File using SAX Parser in JAVA<\/a><\/li>\n<li><a title=\"XML Tree viewer\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/xml-tree-viewer-using-sax-parser-in-java-with-jtreejfilechooser-component-of-swing\/\" target=\"_blank\">XML Tree Viewer using SAX Parser in JAVA with Jtree, JFileChooser component of Swing<\/a><\/li>\n<\/ul>\n<p>To summarize all, lets discuss difference between both approach.<\/p>\n<p><strong><!--more-->SAX Parser:<\/strong><\/p>\n<ol>\n<li>Event based model.<\/li>\n<li>Serial access (flow of events).<\/li>\n<li>Low memory usage (only events are generated).<\/li>\n<li>To process parts of the document (catching relevant events).<\/li>\n<li>To process the document only once.<\/li>\n<li>Backward navigation is not possible as it sequentially processes the document.<\/li>\n<li>Objects are to be created.<\/li>\n<\/ol>\n<p><strong>DOM Parser:<\/strong><\/p>\n<ol>\n<li>(Object based)Tree data structure.<\/li>\n<li>Random access (in-memory data structure).<\/li>\n<li>High memory usage (the document is loaded into memory).<\/li>\n<li>To edit the document (processing the in-memory data structure).<\/li>\n<li>To process multiple times (document loaded in memory).<\/li>\n<li>Ease of navigation.<\/li>\n<li>Stored as objects.<\/li>\n<\/ol>\n<p>For simpler applications, that complexity may well be unnecessary. For faster development and simpler applications, one of the object-oriented XML-programming standards, such as <strong>JDOM <\/strong>( <a title=\"JDOM\" href=\"http:\/\/www.jdom.org\" target=\"_blank\">http:\/\/www.jdom.org<\/a>) and <strong>DOM4J <\/strong>( <a title=\"DOM4j\" href=\"http:\/\/dom4j.org\/\" target=\"_blank\">http:\/\/dom4j.org\/<\/a>), might make more sense.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is the difference between SAX And DOM Parsers<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[3],"tags":[227],"class_list":["post-1774","post","type-post","status-publish","format-standard","hentry","category-java","tag-xml"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1742,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/introduction-to-jaxp\/","url_meta":{"origin":1774,"position":0},"title":"Introduction to JAXP and Difference between JAXP and JAXB","author":"Jitendra","date":"March 22, 2011","format":false,"excerpt":"Introduction to JAXP (JAVA API for XML Processing), SAX (Simple API for XML Parsing),Extensible Style sheet language transformation (XSLT)","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"XML Processing using DOM in JAXP","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/XML-Processing-using-DOM-in-JAXP.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1750,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/create-xml-file-using-jaxp-and-transformation-apis\/","url_meta":{"origin":1774,"position":1},"title":"Create XML File using DOM Parser of JAXP and Transformation APIs","author":"Jitendra","date":"March 22, 2011","format":false,"excerpt":"Example of Creating XML File using JAXP and Transformation APIs","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1756,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/searching-xml-file-using-dom-parser-of-jaxp\/","url_meta":{"origin":1774,"position":2},"title":"Searching XML File using DOM Parser of JAXP","author":"Jitendra","date":"March 22, 2011","format":false,"excerpt":"Example of Searching XML File using DOM Parser of JAXP","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1753,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/traverse-xml-file-using-dom-parser-of-jaxp\/","url_meta":{"origin":1774,"position":3},"title":"Traverse XML file using DOM Parser of JAXP","author":"Jitendra","date":"March 22, 2011","format":false,"excerpt":"Example of Traverse XML file using DOM Parser of JAXP","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2120,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/validate-xml-schema-using-dom-parser-and-sax-parser-in-java-using-swing\/","url_meta":{"origin":1774,"position":4},"title":"Validate XML Schema Using DOM Parser and SAX Parser in JAVA Using Swing","author":"Jitendra","date":"May 13, 2011","format":false,"excerpt":"Validate XML Schema Using DOM Parser and SAX Parser in JAVA Using Swing","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Input Screen - XML Schema Validation in JAVA Using DOM and SAX Parser","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/05\/Input-Screen-XML-Schema-Validation-in-JAVA-Using-DOM-and-SAX-Parser.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1764,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/read-xml-file-using-sax-parser-in-java\/","url_meta":{"origin":1774,"position":5},"title":"Read XML File using SAX Parser in JAVA","author":"Jitendra","date":"March 22, 2011","format":false,"excerpt":"Example of Reading XML File using SAX Parser in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"SAX Parser","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/SAX-Parser.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1774"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1774\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}