What are the two basic XML parsing models? Describe how they are different from each other and when each might be used.
There are two basic types of XML parsing models-
1) DOM (Document Object Model)
DOM is a tree-based model that creates an internal strcuture of the
XML document as a tree of nodes. This tree can be searched for
nodes, and these nodes can be read and updated by the client
application.
DOM model is generally used for small documents, because it is
memory inefficient, since it uses up more memory for loading whole
XML document into memory.
DOM models are commonly used for browsers, editors etc.
2) SAX (Simple API for XML)
SAX is an event-driven model. It doesn't create any internal
structure of the XML. Instead, an event-based API sends parsing
events directly to the client application through callbacks, and
the application implements handlers to deal with the different
events. In SAX, it is not possible to navigate through the document
like with a DOM model. Also, SAX is read only i.e. can’t insert or
delete data.
SAX models are generally used for large documents as they memory
efficient (uses up no extra memory to store XML document content)
as comapred to DOM models.
Get Answers For Free
Most questions answered within 1 hours.