0% found this document useful (0 votes)
31 views

Dom - Sax

This document compares DOM and SAX parsers for XML documents. DOM stores the entire XML document in memory before processing, allows inserting and deleting nodes, and traversing in any direction but uses more memory and runs slower. SAX parses nodes sequentially without storing the XML in memory, cannot modify nodes, and runs faster but does not preserve comments. The document also provides code samples for using SAX to parse an XML file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Dom - Sax

This document compares DOM and SAX parsers for XML documents. DOM stores the entire XML document in memory before processing, allows inserting and deleting nodes, and traversing in any direction but uses more memory and runs slower. SAX parses nodes sequentially without storing the XML in memory, cannot modify nodes, and runs faster but does not preserve comments. The document also provides code samples for using SAX to parse an XML file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DOM SAX

Nguyn ng Khoa
Comparison
DOM
Stores the
entire XML document into
memory before processing
Occupies more memory
We can insert or delete nodes
Traverse in any direction.
DOM is a tree model parser
Document Object
Model (DOM) API
Preserves comments
DOM generally runs a little
slower than SAX

SAX
Parses node by node
Doesnt store the XML in
memory
We cant insert or delete a
node
SAX is an event based parser
SAX is a Simple API for XML
doesnt preserve comments
SAX generally runs a little
faster than DOM

DOM
Reference:
http://www.slideshare.net/martyhall/java-7-
programming-tutorial-parsing-xml-files-with-
the-dom-api

SAX
1. Create Factory object

2. Create Parser object from factory object

3. Create Handler object by using
DefaultHandler class

4. Read xml file by using Parser and Handler
SAX
SAXParserFactory factory =
SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {}
saxParser.parse("test.xml", handler);
SAX DefaultHandler Override
methods

You might also like