SlideShare a Scribd company logo
1 of 3
Download to read offline
Web Technology ECS-604
Lecture No. 12
XML DOM
The XML DOM defines a standard for accessing and manipulating XML.
What is the DOM?
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents like XML and HTML:
The W3C Document Object Model (DOM) is a platform and language-neutral interface that
allows programs and scripts to dynamically access and update the content, structure, and
style of a document.
The DOM is separated into 3 different parts / levels:
Core DOM - standard model for any structured document
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
The DOM defines the objects and properties of all document elements, and
the methods (interface) to access them.
What is the XML DOM?
The XML DOM is:
A standard object model for XML
A standard programming interface for XML
Platform- and language-independent
A W3C standard
The XML DOM defines the objects and properties of all XML elements, and
the methods (interface) to access them.
In other words: The XML DOM is a standard for how to get, change, add, or delete
XML elements.
SAX
SAX (Simple API for XML) is an event-based sequential access parser API developed by the XML-DEV
mailing list for XMLdocuments SAX provides a mechanism for reading data from an XML document that is an
alternative to that provided by the Document Object Model (DOM). Where the DOM operates on the document
as a whole, SAX parsers operate on each piece of the XML document sequentially.
Web Technology ECS-604
Unlike DOM, there is no formal specification for SAX. The Java implementation of SAX is considered to
be normative. SAX processes documents state-independently, in contrast to DOM which is used for state-
dependent processing of XML documents.
Benefits
SAX parsers have some benefits over DOM-style parsers. A SAX parser only needs to report each parsing
event as it happens, and normally discards almost all of that information once reported (it does, however, keep
some things, for example a list of all elements that have not been closed yet, in order to catch later errors such
as end-tags in the wrong order). Thus, the minimum memory required for a SAX parser is proportional to the
maximum depth of the XML file (i.e., of the XML tree) and the maximum data involved in a single XML event
(such as the name and attributes of a single start-tag, or the content of a processing instruction, etc.).
This much memory is usually considered negligible. A DOM parser, in contrast, typically builds a tree
representation of the entire document in memory to begin with, thus using memory that increases with the
entire document length. This takes considerable time and space for large documents (memory allocation and
data-structure construction take time). The compensating advantage, of course, is that once loaded any part of
the document can be accessed in any order.
Drawbacks
The event-driven model of SAX is useful for XML parsing, but it does have certain drawbacks.
Virtually any kind of XML validation requires access to the document in full. The most trivial example is that an
attribute declared in the DTD to be of type IDREF, requires that there be an element in the document that uses
the same value for an ID attribute. To validate this in a SAX parser, one must keep track of all ID attributes (any
one of them might end up being referenced by an IDREF attribute at the very end); as well as every IDREF
attribute until it is resolved. Similarly, to validate that each element has an acceptable sequence of child
elements, information about what child elements have been seen for each parent, must be kept until the parent
closes.
XML processing with SAX
A parser that implements SAX (i.e., a SAX Parser) functions as a stream parser, with an event-driven API. The
user defines a number of callback methods that will be called when events occur during parsing. The SAX
events include (among others):
XML Text nodes
XML Element Starts and Ends
XML Processing Instructions
XML Comments
Some events correspond to XML objects that are easily returned all at once, such as comments. However,
XML elements can contain many other XML objects, and so SAX represents them as does XML itself: by one
event at the beginning, and another at the end. Properly speaking, the SAX interface does not deal
in elements, but in events that largely correspond to tags. SAX parsing is unidirectional; previously parsed data
cannot be re-read without starting the parsing operation again.
There are many SAX-like implementations in existence. In practice, details vary, but the overall model is the
same. For example, XML attributes are typically provided as name and value arguments passed to element
events, but can also be provided as separate events, or via a hash or similar collection of all the attributes. For
Web Technology ECS-604
another, some implementations provide "Init" and "Fin" callbacks for the very start and end of parsing; others
don't. The exact names for given event types also vary slightly between implementations.

More Related Content

What's hot (20)

Session 5
Session 5Session 5
Session 5
 
Dom parser
Dom parserDom parser
Dom parser
 
XML and Databases
XML and DatabasesXML and Databases
XML and Databases
 
Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
Xml databases
Xml databasesXml databases
Xml databases
 
Xml parsing
Xml parsingXml parsing
Xml parsing
 
XML Databases
XML DatabasesXML Databases
XML Databases
 
XMl
XMlXMl
XMl
 
XML
XMLXML
XML
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
Xml dom
Xml domXml dom
Xml dom
 
Xml
XmlXml
Xml
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based Applications
 
Data exchange over internet (XML vs JSON)
Data exchange over internet (XML vs JSON)Data exchange over internet (XML vs JSON)
Data exchange over internet (XML vs JSON)
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databases
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 

Viewers also liked (17)

uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
Unit 2.1
Unit 2.1Unit 2.1
Unit 2.1
 
Css2
Css2Css2
Css2
 
Html
HtmlHtml
Html
 
Unit 1
Unit 1Unit 1
Unit 1
 
Jsp
JspJsp
Jsp
 
Routers and planes (1)
Routers and planes (1)Routers and planes (1)
Routers and planes (1)
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Flow control 11
Flow control 11Flow control 11
Flow control 11
 
Unit 1 web technology uptu slide
Unit 1 web technology uptu slideUnit 1 web technology uptu slide
Unit 1 web technology uptu slide
 
Xml
XmlXml
Xml
 
1
11
1
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Explicit congestion notification
Explicit congestion notificationExplicit congestion notification
Explicit congestion notification
 
Java script
Java scriptJava script
Java script
 
Dsdv
DsdvDsdv
Dsdv
 

Similar to XML DOM and SAX Explained for Web Technology Course

Similar to XML DOM and SAX Explained for Web Technology Course (20)

Xml and xml processor
Xml and xml processorXml and xml processor
Xml and xml processor
 
Applied xml programming for microsoft
Applied xml programming for microsoftApplied xml programming for microsoft
Applied xml programming for microsoft
 
XML Tutor maXbox starter27
XML Tutor maXbox starter27XML Tutor maXbox starter27
XML Tutor maXbox starter27
 
X Usax Pdf
X Usax PdfX Usax Pdf
X Usax Pdf
 
Enhanced xml validation using srml01
Enhanced xml validation using srml01Enhanced xml validation using srml01
Enhanced xml validation using srml01
 
Xml
XmlXml
Xml
 
E05412327
E05412327E05412327
E05412327
 
CTDA Workshop on XML and MODS
CTDA Workshop on XML and MODSCTDA Workshop on XML and MODS
CTDA Workshop on XML and MODS
 
Web services Overview in depth
Web services Overview in depthWeb services Overview in depth
Web services Overview in depth
 
XML - SAX
XML - SAXXML - SAX
XML - SAX
 
Understanding Sax
Understanding SaxUnderstanding Sax
Understanding Sax
 
Web data management (chapter-1)
Web data management (chapter-1)Web data management (chapter-1)
Web data management (chapter-1)
 
Oracle soa xml faq
Oracle soa xml faqOracle soa xml faq
Oracle soa xml faq
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
 
[DSBW Spring 2010] Unit 10: XML and Web And beyond
[DSBW Spring 2010] Unit 10: XML and Web And beyond[DSBW Spring 2010] Unit 10: XML and Web And beyond
[DSBW Spring 2010] Unit 10: XML and Web And beyond
 
advDBMS_XML.pptx
advDBMS_XML.pptxadvDBMS_XML.pptx
advDBMS_XML.pptx
 
XML
XMLXML
XML
 
XML, XML Databases and MPEG-7
XML, XML Databases and MPEG-7XML, XML Databases and MPEG-7
XML, XML Databases and MPEG-7
 
Markup For Dummies (Russ Ward)
Markup For Dummies (Russ Ward)Markup For Dummies (Russ Ward)
Markup For Dummies (Russ Ward)
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 

More from Abhishek Kesharwani (20)

uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 
uptu web technology unit 2 Css
uptu web technology unit 2 Cssuptu web technology unit 2 Css
uptu web technology unit 2 Css
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
 
Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1 Unit1 Web Technology UPTU UNIT 1
Unit1 Web Technology UPTU UNIT 1
 
Unit1 2
Unit1 2 Unit1 2
Unit1 2
 
Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1 Web Technology UPTU UNIT 1
Web Technology UPTU UNIT 1
 
Mtech syllabus computer science uptu
Mtech syllabus computer science uptu Mtech syllabus computer science uptu
Mtech syllabus computer science uptu
 
Wi max tutorial
Wi max tutorialWi max tutorial
Wi max tutorial
 
Virtual lan
Virtual lanVirtual lan
Virtual lan
 
Tcp traffic control and red ecn
Tcp traffic control and red ecnTcp traffic control and red ecn
Tcp traffic control and red ecn
 
Schedulling
SchedullingSchedulling
Schedulling
 
Scheduling
SchedulingScheduling
Scheduling
 
Rsa example
Rsa exampleRsa example
Rsa example
 
Routers and planes
Routers and planesRouters and planes
Routers and planes
 
Rip ospf and bgp
Rip ospf and bgpRip ospf and bgp
Rip ospf and bgp
 
Qo s rsvp......
Qo s rsvp......Qo s rsvp......
Qo s rsvp......
 
Qo s 09-integrated and red
Qo s 09-integrated and redQo s 09-integrated and red
Qo s 09-integrated and red
 

XML DOM and SAX Explained for Web Technology Course

  • 1. Web Technology ECS-604 Lecture No. 12 XML DOM The XML DOM defines a standard for accessing and manipulating XML. What is the DOM? The DOM is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents like XML and HTML: The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document. The DOM is separated into 3 different parts / levels: Core DOM - standard model for any structured document XML DOM - standard model for XML documents HTML DOM - standard model for HTML documents The DOM defines the objects and properties of all document elements, and the methods (interface) to access them. What is the XML DOM? The XML DOM is: A standard object model for XML A standard programming interface for XML Platform- and language-independent A W3C standard The XML DOM defines the objects and properties of all XML elements, and the methods (interface) to access them. In other words: The XML DOM is a standard for how to get, change, add, or delete XML elements. SAX SAX (Simple API for XML) is an event-based sequential access parser API developed by the XML-DEV mailing list for XMLdocuments SAX provides a mechanism for reading data from an XML document that is an alternative to that provided by the Document Object Model (DOM). Where the DOM operates on the document as a whole, SAX parsers operate on each piece of the XML document sequentially.
  • 2. Web Technology ECS-604 Unlike DOM, there is no formal specification for SAX. The Java implementation of SAX is considered to be normative. SAX processes documents state-independently, in contrast to DOM which is used for state- dependent processing of XML documents. Benefits SAX parsers have some benefits over DOM-style parsers. A SAX parser only needs to report each parsing event as it happens, and normally discards almost all of that information once reported (it does, however, keep some things, for example a list of all elements that have not been closed yet, in order to catch later errors such as end-tags in the wrong order). Thus, the minimum memory required for a SAX parser is proportional to the maximum depth of the XML file (i.e., of the XML tree) and the maximum data involved in a single XML event (such as the name and attributes of a single start-tag, or the content of a processing instruction, etc.). This much memory is usually considered negligible. A DOM parser, in contrast, typically builds a tree representation of the entire document in memory to begin with, thus using memory that increases with the entire document length. This takes considerable time and space for large documents (memory allocation and data-structure construction take time). The compensating advantage, of course, is that once loaded any part of the document can be accessed in any order. Drawbacks The event-driven model of SAX is useful for XML parsing, but it does have certain drawbacks. Virtually any kind of XML validation requires access to the document in full. The most trivial example is that an attribute declared in the DTD to be of type IDREF, requires that there be an element in the document that uses the same value for an ID attribute. To validate this in a SAX parser, one must keep track of all ID attributes (any one of them might end up being referenced by an IDREF attribute at the very end); as well as every IDREF attribute until it is resolved. Similarly, to validate that each element has an acceptable sequence of child elements, information about what child elements have been seen for each parent, must be kept until the parent closes. XML processing with SAX A parser that implements SAX (i.e., a SAX Parser) functions as a stream parser, with an event-driven API. The user defines a number of callback methods that will be called when events occur during parsing. The SAX events include (among others): XML Text nodes XML Element Starts and Ends XML Processing Instructions XML Comments Some events correspond to XML objects that are easily returned all at once, such as comments. However, XML elements can contain many other XML objects, and so SAX represents them as does XML itself: by one event at the beginning, and another at the end. Properly speaking, the SAX interface does not deal in elements, but in events that largely correspond to tags. SAX parsing is unidirectional; previously parsed data cannot be re-read without starting the parsing operation again. There are many SAX-like implementations in existence. In practice, details vary, but the overall model is the same. For example, XML attributes are typically provided as name and value arguments passed to element events, but can also be provided as separate events, or via a hash or similar collection of all the attributes. For
  • 3. Web Technology ECS-604 another, some implementations provide "Init" and "Fin" callbacks for the very start and end of parsing; others don't. The exact names for given event types also vary slightly between implementations.