In practical: book.xml
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
</bookstore>
- DOM presents the xml document as a the following tree-structure in memory.
- DOM is W3C standard.
- DOM parser works on Document Object Model.
- DOM occupies more memory, preferred for small XML documents
- DOM is Easy to navigate either forward or backward.
- SAX presents the xml document as event based like
start element:abc
, end element:abc
.
- SAX is not W3C standard, it was developed by group of developers.
- SAX does not use memory, preferred for large XML documents.
- Backward navigation is not possible as it sequentially process the documents.
- Event happens to a node/element and it gives all sub nodes(Latin nodus, ‘knot’).
This XML document, when passed through a SAX parser, will generate a sequence of events like the following:
start element: bookstore
start element: book with an attribute category equal to cooking
start element: title with an attribute lang equal to en
Text node, with data equal to Everyday Italian
....
end element: title
.....
end element: book
end element: bookstore