The XML object model is a collection of objects that is used to access and manipulate the data stored in an XML document. The XML document is modeled like a tree, in which each element in the tree is considered a node. Objects with various properties and methods are used to traverse the tree and its nodes. Each node contains the data in the document.
An XML parser is a software package, a libraray or a module that reads XML documents first. The information present in the XML file is then made available by the parser to applications and other programming languages
It is important to parse XML data efficiently, especially in applications that handle large volumes of data. Improper parsing will result in excessive memory usage and processing time that will hamper scalability.
Create by ChungLD faculty /31 Parsing Event-driven Parsing Object-based Parsing
SAX gives an event based approach to XML parsing. In an event based parsing when the parser encounters an element, the parser returns the elements, its attribute and content. Event based parsing provides a data – centric view of XML. Events include XML tag, detecting errors and so on.
Low memory consumption as the entire XML document is not loaded in the memory
No built-in document navigation support
No support for random access of XML document
No namespace and modifying XML document support in place
DOM is a mature standard from W3C. DOM parser builds a hierarchical model of the parsed document. Each of the important locations in the document, various element and attribute containers and characteristics of the model is represented as nodes.
Easy to use. Easy navigation by using the APIs. Random access to XML document as the tree is loaded in the memory
Parsing of the XML document is done once. High memory consumption and expensive as the entire tree structure is loaded in the memory
The StAX is a new parsing model introduced recently. Like SAX it is an event-driven model. StAX uses pull model for event processing. In other words, StAX parser returns events that are requested by an application and the events can also be provided as objects.
Ease in performance as it supports two parsing models. Parsing controlled by application
An element is a Node object and hence inherits the properties and methods of the Node interface. The method getElementsByTagName() returns a nodeList of the elements and the length() method can be used to loop through the list.
The NodeList object represents a collection of Node objects. Any alterations to the properties of node are reflected in the list. Individual nodes can be accessed using indexes as well as one can iterate through the collection.
Create by ChungLD faculty /31 Click and see
Traversing a DOM Tree using NameNodeMap Object
NameNodeMap object represents a collection of nodes that is accessed by name.
The Attribute of an element object is represented by the Attr interface and is defined in DTD. The Attr object is a node and inherits the properties and methods of the Node object. Attribute is a property of a child node and not a child node. An attribute does not have a parent node.
The XMLDOMPaserError object is an extension to the W3C specification. It can be used to get detailed information on the last error that occurred while either loading or parsing a document. The XMLDOMParseError
SAX is not a W3C standard and has well-deffined APIs for parsing XML document. SAX generates events as it reads through the document and the event handlers handle these events and provide access to the content of the XML document
This is the default base class for SAX2 event handlers, it provides defalt implementations for all of the callbacks in the four core SAX2 handler classes: Entityresolver, DTDHandler, ContentHandler, ErrorHandler.