XML Parsers

In this section, you will learn about the XML parsers. The XML parser is used to read, update, create and manipulate an XML document.

Ads

Tutorials   
JAXB Create XML File And Get Data From XML XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials The Simple API for XML (SAX) APIs Part I XML,XML Tutorials,Online XML Tutorial,XML Help Tutorials XML Tutorial Ignoring Comments While Parsing an XML File Accessing XML file from Java Preventing Expansion of Entity References Getting next Tag in the XML File Replacing a Node with a New One Reading XML Data from a Stream Reading an XML document using JDOM Query XML with an XPath expression Normalize All of the Text in a Document Modifying Text by Replacement Insert a Processing Instruction and a Comment Node Getting text values from a NodeList Finding an ID Value and Print the Element Text Edit Text by Insertion and Replacement Duplicating a Subtree Deleting Two Attributes Delete the First Child of the Root Node Creating XML Tree Creating a DocumentFragment Subtree and Appending it to the Document Creates element node, attribute node, comment node, processing instruction and a CDATA section Creates a New DOM Parse Tree Replacing a Text Node with a New CDATA Section Node Create an Empty DOM Document Adding an Attribute in DOM Document Transforming XML with XSLT Transforming an XML File with XSL Transforming XML with SAXFilters Storing properties in XML file Testing EntityReferences in Xml Splitting One Text Node into Three Reading XML from a File Modifying Text by Cutting and Pasting Locating a Node by Using Siblings Locate a Node and Change Its Content Loading properties from a XML file Listing nodes used in a document Inserting a New Entry in a List Creating an InlineStreamFilter Ignoring Comments While Parsing an XML File Handling Errors While Parsing an XML File Emitting DOCTYPE Declaration while writing XML File Converting CDATA Nodes into Text Nodes Java DOM Tutorial Creating Blank DOM Document
Ads

XML Parsers

     

XML parser is used to read, update, create and manipulate an XML document.

Parsing XML Documents

To manipulate an XML document, XML parser is needed. The parser loads the document into the  computer's memory. Once the document is loaded, its data can be manipulated using the appropriate parser. 

We will soon discuss APIs and parsers for accessing XML documents using serially accesss mode (SAX) and  random access mode (DOM). The specifications to ensure the validity of XML documents are DTDs  and the Schemas.

DOM: Document Object Model

The XML Document Object Model (XML DOM) defines a standard way to access and manipulate XML documents using any programming language (and a parser for that language).

The DOM presents an XML document as a tree-structure (a node tree), with the elements, attributes, and text defined as nodes. DOM provides access to the information stored in your XML document as a hierarchical object model.

The DOM converts an XML document into a collection of objects in a object model in a tree structure (which  can be manipulated  in any way ). The textual information in  XML document gets turned into a bunch of tree nodes and an user can easily traverse through any part of the  object tree,  any time. This makes easier to modify the data, to remove it, or even to insert a new one. This mechanism is also known as the random access protocol .

DOM is very useful when the document is small. DOM  reads the entire XML structure and holds the object tree in memory, so it is much more CPU and memory intensive. The DOM  is most suited for interactive applications because the entire object model is present in memory, where it can be accessed and manipulated by the user.

SAX: Simple API for XML

This API was an innovation, made  on the XML-DEV mailing list through a product collaboration, rather than being a product of the W3C.

SAX (Simple API for XML) like DOM  gives access to the information stored in XML documents using any programming language (and a parser for that language).

This standard API works in serial access  mode to parse XML documents. This is a very fast-to-execute mechanism employed to read and write XML data comparing to its  competitors. SAX tells the application, what is in the document by notifying through a stream of parsing events. Application then processes those events to act on data.

SAX is also called as an event-driven protocol, because it implements the technique  to register the handler  to invoke the callback methods whenever an event is generated. Event is generated when the parser encounters a new XML tag or encounters an error, or wants to tell  anything else. SAX is memory-efficient to a great extend.

SAX is very useful when the document is large.

DOM  reads the entire XML structure and holds the object tree in memory, so it is much more CPU and memory intensive. For that reason, the SAX API  are preferred for server-side applications and data filters that do not require any memory intensive representation of the data.

     

Advertisements

Share on Google+Share on Google+

XML Parsers

Posted on: May 25, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: XML Parsers   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads