XML Parsers

XML Parsers       

       1.       Validating Parsers
       2.       Non Validating Parsers

    There are two different implementation approaches to processing the XML data:
  • Event-driven parser -Processes XML data sequentially, handling components one at a time
  • Tree-based parser -Constructs a tree representation of the entire document and provides access to individual nodes in the tree (can be constructed on top of an event-driven parser)

        XPATH –To Travers an XML document (used with XSLT)
        DOM –To Modify an XML document.
        SAX –To traverse an XML document.

DOM – Document Object Model API


1.    Most browsers have this to display the XML content.
2.    It makes the tags to HTML by providing to ID to it.
3.    It represents document as a inverted structure in memory (as Binary Tree)
4.    Searching is fast on DOM because of tree structure.
5.    Allow dynamic update of contents


DOM API
1.       The main objects and methods provided by XML DOM that enable you to traverse, read and manipulate the structure and content of an XML document are listed below.
2.       DOMDocument Object : This object represents the complete XML document.
·         You must create an instance of this object to work with any XML document.
·         This objects exposes a set of properties and methods to manipulate XML documents


SAX
1.    SAX (Simple API for XML) is a standard interface for event-driven XML parsers.
2.    SAX parser reads the XML data sequentially and signals events for each individual node, which can then be used by an application to process the data.
3.    This event-driven approach is similar to the event-handling model of modern graphical user interfaces (GUIs), and can handle immense XML documents without requiring massive amounts of memory to store a tree model.

Event Driven Parsers -SAX
1.    SAX parser executes a call-back to the application for each component of the XML data.
2.    It's up to the application to handle the XML data as it is provided via the call-backs
3.    The event driven method requires very modest system resources, even for extremely large document
4.    All major event-driven parsers support a standard API, called SAX (Simple API for XML), with two versions available:
·         SAX1
·         and SAX2.

When to use DOM
1.    When you want to modify and save XML
2.    The DOM is the better choice for modifying an XML document and saving the changed document to memory.
3.    SAX is designed for reading, not writing, XML
4.    When you want to modify and save XML
5.    The DOM is the better choice for modifying an XML document and saving the changed document to memory.
6.    SAX is designed for reading, not writing, XML

When to use SAX
 When your documents are large
1.    The biggest advantage of SAX is that it requires significantly less memory to process an XML document than the DOM.
2.    SAX is the better alternative, particularly if you do not need to change the contents of the document.
When you need to abort parsing
1.    Because SAX allows you to abort processing at any time, you can use it to create applications that fetch particular data.
2.    For example, you can create an application that searches for a part in inventory. When the application finds the part, it returns the part number and availability, and then stops processing.
When you want to retrieve small amounts of information
1.    For many XML-based solutions, it is not necessary to read the entire document to achieve the desired results.
2.    For example, if you want to scan data for relevant news about a particular stock, it's inefficient to read the unnecessary data into memory.
3.    With SAX, your application can scan the data for news related only to the stock symbols you indicate, and then create a slimmed-down document structure to pass along to a news service. 

When to use XLINK

1.    XLINK (XML Linking Language) -is a specification for enhanced linking capabilities.
2.    XLINK allows XML documents to establish a linking relationship between more than one document.
3.    In HTML you have the <A> ANCHOR tag which can be used to link a document to another. In XML , any element can become a source of a link.