1. SAX
Simple API for XML (SAX)
SARASWATHI RAMALINGAM
SRI AKILANDESWARI WOMENS COLLEGE
2. SAX
• Both DOM and the Simple API for XML
(SAX) provide a programmatic layer that
allows a user to directly access the
information contained within an XML
document.
• However, each of these mechanisms
provides a different approach to accessing
this information.
3. SAX
• Whereas DOM creates an object that
represents a hierarchical tree of nodes that
reflects the structure of an XML document,
– SAX processes an XML document by giving
applications a stream of parsing events around
that document.
4. SAX
• Rather than interacting with an in-memory
XML tree, a user is interacting with a stream of
data that can be acted upon.
• DOM is great for in-memory tree manipulation,
whereas SAX is great for linear processing of
large XML documents.
• Event-based parsers such as SAX provide a
view of XML documents that is data centric
and event driven.
5. SAX
• DOM can also be used for creating
documents. Unlike DOM, SAX can only be
used for parsing existing documents.
• parser for the English language might break
up a document into paragraphs, words, and
punctuation.
• In the case of XML, the important pieces of
data include elements, attributes, text, and
so on. This is what SAX does.
6. SAX
• Some SAX parsers can validate a document
against a Document Type Definition (DTD).
• Validating parsers can also tell you
specifically where validation has failed.
7. SAX
• DOM is an in-memory tree structure of an
XML document or document fragment.
•
• DOM is a natural object model of an XML
document, but it’s not always practical.
• Large documents can take up a lot of
memory.
8. SAX
• SAX is, in many ways, much simpler than
DOM.
• There is no need to model every possible
type of object that can be found in an XML
document.
• This makes the API easy to understand and
easier to use.
9. SAX
• SAX is an event-based API.
• Instead of loading an entire document into memory all at
once, SAX parsers read documents and notify a client
program when elements, text, comments, and other data of
interest are found.
• SAX parsers send you events continuously, telling you what
was found next.
• The DOM parses XML in space, whereas SAX parses XML in
time.