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

SAX DOMpresentation

There are two main types of XML parsers: DOM (Document Object Model) parsers and SAX (Simple API for XML) parsers. DOM parsers map XML documents into an internal tree structure that can be navigated, while SAX parsers are event-based and notify applications of elements using an event-driven model. Tree-based DOM parsers are generally easier to implement but take more memory, while event-based SAX parsers are more complex for programmers but use less memory for large documents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

SAX DOMpresentation

There are two main types of XML parsers: DOM (Document Object Model) parsers and SAX (Simple API for XML) parsers. DOM parsers map XML documents into an internal tree structure that can be navigated, while SAX parsers are event-based and notify applications of elements using an event-driven model. Tree-based DOM parsers are generally easier to implement but take more memory, while event-based SAX parsers are more complex for programmers but use less memory for large documents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

XML

DOM and SAX


Parsers
Introduction to parsers

 The word parser comes from


compilers

 In a compiler, a parser is the module


that reads and interprets the
programming language.
Introduction to Parsers

 In XML, a
parser is a
software
component
that sits
between the
application
and the XML
files.
Introduction to parsers

 It reads a text-formatted XML file or


stream and converts it to a
document to be manipulated by the
application.
Tree-based parsers

 These map an XML document into an


internal tree structure, and then
allow an application to navigate that
tree.
Event-based
 The application implements handlers
to deal with the different events
Event-based vs. Tree-based
parsers

 Tree-based parsers deal generally


small documents.

 Event-based parsers deal generally


used for large documents.
Event-based vs. Tree-based
parsers

 Tree-based parsers are generally


easier to implement.

 Event-based parsers are more


complex and give hard time for the
programmer
What is DOM?

 The Document Object Model (DOM)


is an application programming
interface (API) for HTML and XML
documents.

 It defines the logical structure of


documents and the way a document
is accessed.
Properties of DOM
 Programmers can build documents,
navigate their structure, and add, modify,
or delete elements and content.

 Provides a standard programming


interface that can be used in a wide
variety of environments and applications.
What DOM is not!!

 The Document Object Model is not a


set of data structures, it is an object
model that specifies interfaces.
DOM into work
<?xml version="1.0"?>
<products>
<product>
<name>XML Editor</name>
<price>499.00</price>
</product>
<product>
<name>DTD Editor</name>
<price>199.00</price>
</product>
<product>
<name>XML Book</name>
<price>19.99</price>
</product>
<product>
<name>XML Training</name>
<price>699.00</price>
</product>
</products>
DOM into work
What is SAX?
 SAX (the Simple API for XML) is an event-
based parser for xml documents.

 The parser tells the application what is in


the document.

 Application then processes those events to


act on data.
Why SAX?

 Event-based interface consumes


fewer resources than an object-
based one

 With an event-based interface, the


application can start processing the
document as the parser is reading it
Limitations of SAX

 With SAX, it is not possible to


navigate through the document as
you can with a DOM.
SAX API

 Parser events are similar to user-


interface events such as ONCLICK (in
a browser) or AWT events (in Java).

 Events alert the application that


something happened and the
application might want to react.
SAX Example

<?xml version="1.0"?>
<doc>
<para>Hello, world!</para>
</doc>
SAX example

 start document
 start element: doc
 start element: para
 characters: Hello, world!
 end element: para
 end element: doc
 end document

You might also like