Attributes Entitites   «Prev  Next»

Lesson 3Survey of existing parsers and their uses
Objective Differentiate between types of parsers and their uses.

Existing XML parsers

XML parsers may be categorized using the following taxonomy:
  1. Validating and non-validating parsers
  2. Parsers that support the Document Object Model (DOM) API
  3. Parsers that support the Simple API for XML (SAX) API
  4. Parsers that support both DOM and SAX APIs

Non-validating XML parsers

Non-validating XML parsers check the well-formedness of an XML document. These parsers ignore any reference to a DTD within the XML document. Validating parsers check the validity of an XML document against a specified DTD in addition to its well-formedness. Note that well-formedness checking is a minimum requirement for XML parsers. The distinguishing factor between parsers that support the DOM API and those that support the SAX API lies in the methodology that is used to provide access to parsed content. DOM parsers include a library of methods that may be invoked by a processing application to act on the constructed document hierarchy. Note the sequence of events. I wasn't sure if the "sequence of events" referred to the following section of the paragraph. Because a sequence is implied, I've placed each event in an ordered list. From this sequence, it's not clear to me what the relationship/distinction between the DOM and SAX parser is.

  1. The parser creates the document hierarchy.
  2. Processing applications gain access to the document hierarchy after it is created.
  3. Parsers that support the SAX API define a library of methods that allow a processing application to interact with the parsing process.

Choosing XML Parser

The choice of which parser to use depends on two factors: performance and completeness. Non-validating parsers are faster than validating parsers because they need not incur the additional work of checking the document against a DTD. In cases where the document is known to be valid and all that is required is to gain access to the document data, a non-validating parser will work better. Choosing between parsers that support the DOM versus parsers that support the SAX model depends on whether the processing application needs access to the complete contents of the document or just parts of it. In cases where the processing application needs access to the entire document, use a DOM parser. Use a SAX parser in cases where the processing application is only concerned with certain parts of a given document. The next lesson outlines the steps for using an XML parser.

Existing XML Parsers - Exercise

If you are using IE 5.x, this optional exercise will allow you to parse an XML file in your browser.
Existing XML Parsers - Exercise