0% found this document useful (0 votes)
63 views1 page

4th Question

The document compares DOM and SAX parsers. - SAX parsers read XML documents sequentially and report parsing events to the application without building an in-memory document structure. This uses less memory but provides less functionality. - DOM parsers build a complete in-memory document structure that can then be randomly accessed and manipulated. This uses more memory but provides richer functionality like modifying the document tree. - Whether to use SAX or DOM depends on factors like the document size, need for random access or modifications, and available memory. SAX generally uses less memory and runs faster while DOM provides more flexibility.

Uploaded by

seshu babu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views1 page

4th Question

The document compares DOM and SAX parsers. - SAX parsers read XML documents sequentially and report parsing events to the application without building an in-memory document structure. This uses less memory but provides less functionality. - DOM parsers build a complete in-memory document structure that can then be randomly accessed and manipulated. This uses more memory but provides richer functionality like modifying the document tree. - Whether to use SAX or DOM depends on factors like the document size, need for random access or modifications, and available memory. SAX generally uses less memory and runs faster while DOM provides more flexibility.

Uploaded by

seshu babu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

4.

Differences between DOM&SAX Processors:

SAX Parser: A SAX (Simple API for XML) parser does not create any internal structure. Instead, it takes the occurrences of components of an input document as events, and tells the client what it reads as it reads through the input document. A SAX parser serves the client application always only with pieces of the document at any given time. A SAX parser, however, is much more space efficient in case of a big input document (because it creates no internal structure). Whats more, it runs faster and is easier to learn than DOM parser because its API is really simple. But from the functionality point of view, it provides a fewer functions, which means that the users themselves have to take care of more, such as creating their own data structures. DOM Parser: A DOM (Document Object Model) parser creates a tree structure in memory from an input document and then waits for requests from client. A DOM parser always serves the client application with the entire document no matter how much is actually needed by the client. A DOM parser is rich in functionality. It creates a DOM tree in memory and allows you to access any part of the document repeatedly and allows you to modify the DOM tree. But it is space inefficient when the document is huge, and it takes a little bit longer to learn how to work with it.
SAX DOM Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation. Stores the entire XML document into memory Parses node by node before processing Doesnt store the XML in memory Occupies more memory We cant insert or delete a node We can insert or delete nodes Top to bottom traversing Traverse in any direction. SAX is an event based parser DOM is a tree model parser SAX is a Simple API for XML Document Object Model (DOM) API import javax.xml.parsers.*; import javax.xml.parsers.*; import org.xml.sax.*; import org.w3c.dom.*; import org.xml.sax.helpers.*; doesnt preserve comments preserves comments SAX generally runs a little faster than DOM SAX generally runs a little faster than DOM If we need to find a node and doesnt need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory. In Breif : 1. sax is an event based parser and raise and event, while dom is not 2. sax is forward only where as dom can acess both was forward as well as backwards. 3. sax parses the file as it reads where as the dom loads the file into memory to parse the file. 4. Sax does not have memory constraints where as the dom has momory constraints as xml file is loaded into the memory to parse the file. 5. sax is read only , dom is read and write both. 6. if you have to parse and use the content only once , consider using sax if the xml file and content are used extensively then consider using dom

You might also like