faqts : Computers : Programming : Languages : Delphi : XML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

79 of 103 people (77%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Delphi: XML: Parser: SAX: DOM: What is the difference between the SAX and DOM parser?

Feb 17th, 2007 07:26
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden - 2 August 2003 - 03:50 am ------------------------

Delphi: XML: Parser: SAX: DOM: What is the difference between the SAX 
and DOM parser?

---

There are basically 2 XML parser types:

 1. Tree based parser

 2. Event based parser

===

ad 1. Tree-based parser:

This parser transforms a given XML file first in
a tree structure.
It has to analyze the whole document first.
It provides you with commands to access the elements of the generated
tree.

---

ad 2. Event-based parser

This parser views an XML document as a serie of events.

When a specific event occurs, it calls a developer-provided function to
handle it.

These parsers process the document while doing a tree walk,
from root to branches.

Each time it finds a tag, it calls a corresponding user function
(which e.g. shows the name or value of a tag)

For example the following "Hello-World" XML document

<example>
   Hello World
</example>

An event-based parser would report it as a series of three events:

Start Element: example
Start CDATA section, value: Hello World
Close Element: example


Advantage of tree based parser:

Because tree based XML parsers parse an entire XML file before you can
do anything with the content and if you are working with large files,
this can be costly both in resources and time, particularly when all
you want is a single piece of data buried deep within the file.

Often, you just need to parse a portion of a file or process a file
from start to end, extracting information from specific nodes.

===

DOM: Tree based parser

Creates first an internal representation of an XML document

-Nice for smaller XML files, but because of the whole XML file
 representation is in memory, it is possible not useful for very large
 documents

-good for representation of an XML document.

---

SAX: Event driven parser

Event driven, so reacting when it finds certain elements in the XML
code (e.g. tags,
properties, ...)

goes from top to bottom, and if it encounters

e.g. begintag, it fires an event.
e.g. end tag, it fires and event.
e.g. begin of file, it fires an event

===

Internet: see also:

---

MSXML 3.0 and the Next Generation
http://www.topxml.com/xml/articles/msxml3/

---

http://www.skch.net./

---

http://www.skch.net/download/xml1.pdf

---

http://www.skch.net/download/xml2.pdf

---

http://www.tek-
tips.com/gviewthread.cfm/lev2/4/lev3/29/pid/102/qid/526604

---

http://www.zend.com/zend/art/parsing.php?
article=parsing&kind=a&id=6022&open=1&anc=0&view=1

----------------------------------------------------------------------