Parsing the XML Data

XML Parser is used to convert XML data to and from the DOM tree structure.The end result of the XML parsing is a DOM tree structure. In the case of SMIL, the player can use this DOM tree to render the slides.

Introduction

In order to parse XML data, an instance of the parser must be created. Two types of constructors exist, one type takes a MXMLDtd object, while the other does not. If a DTD object is supplied, then the parser validates the XML according to that DTD. If no DTD class is provided, then no validation takes place.

All of the constructors take a MMDXMLParserObserver parameter. This interface is usually implemented by the owning class which then passes itself to the parser constructor. This interface exists so that the parser can notify its owner when parsing is complete.

The way in which the DOM tree is used varies depending on the type of XML and even between different clients of the same type of XML. Different SMIL players may walk the DOM tree in slightly different ways; however several functions are likely to be used by all XML clients.

Procedure

  1. Generate a DOM tree from XML data.

  2. Extract the data from the DOM tree.

Generate a DOM tree from XML data

The following are the steps required to parse XML data and get the DOM tree:

  1. Call CMDXMLParser::ParseFile(), passing in the filename of the XML document to be parsed.

    When the parsing is complete, the parser calls the observer's ParseFileCompleteL() function. This function must initiate the handling of the DOM tree that has been generated by the parser.

  2. Call CMDXMLParser::DetachXMLDoc() to take ownership of the parsed DOM tree.

  3. Call CMDXMLDocument::DocumentElement() to get the root element of the DOM tree.

Extract data from the DOM tree

The DOM tree is made up of CMDXMLNode objects. The document element that is returned by the final step of the previous section is an example of a CMDXMLNode.

Use the following functions to navigate the DOM tree:

Once a child or sibling node has been located, it is necessary to cast it to the specific type. The type can be identified by calling CMDXMLNode::NodeType(). The following types of node might exist in a parsed DOM tree. Once the type has been identified, they must be cast to one of the following: