XML Parsers: Types of Parsers Using XML Parsers SAX DOM DOM Versus SAX Products Conclusion
XML Parsers: Types of Parsers Using XML Parsers SAX DOM DOM Versus SAX Products Conclusion
Overview
Types of parsers
SAX
DOM
Products
Conclusion
Types of Parsers
There are several different ways to categorise
parsers:
Validating versus non-validating parsers
Parsers that support the Document Object Model
(DOM)
Parsers that support the Simple API for XML (SAX)
Parsers written in a particular language (Java, C++,
Perl, etc.)
Non-validating Parsers
Speed and efficiency
- It takes a significant amount of effort for an XML
parser to process a DTD and make sure that
every element in an XML document follows the
rules of the DTD.
A
P Application
I
Parsing XML: DOM
DOM Level 2
- includes a style sheet object model
- defines an event model and provides support for
XML namespaces.
DOM Level 3
- still under development
- addresses document loading and saving
- content model (DTDs and schemas) with document validation
support.
Parsing XML: SAX
Simple API for XML
API for accessing xml data
event based
programming language indepedent
application has to store fragments into memory
read only
Parsing XML: SAX
SAX is an interface to the XML parser based on
streaming and call-backs
You need to implement the HandlerBase interface :
startDocument, endDocument
startElement, endElement
characters
warning, error, fatalError
Parsing XML: SAX
SAX:
read only
huge data or streams
data is machine generated
DOM pro and contra
PRO
The file is parsed only once.
High navigation abilities : this is the aim of the DOM design.
CONTRA
More memory needed since the XML tree is in memory.
SAX pro and contra
PRO
Low memory needs since the XML file is never entirely in
memory
Can deal with XML streams
CONTRA
The file has to be parsed entirely to access any node. Thus,
getting the 10 nodes included in a catalog ended up in parsing
10 times the same file.
Poor navigation abilities : no way to get easily the children of a
given node or the list of "B" nodes
SAX versus DOM
If your document is very large and you only need a
few elements - use SAX
Questions?
Thank you!