Parsing XML DOM

This topic explains how to build a DOM tree by parsing an XML file.

Prerequisites

Before you start, you must:

Steps

  1. Call the XmlEnginePushL() method to put parser resources on the clean-up stack.

    Example:

    XmlEnginePushL();
    
  2. Initialise your instance of the RXmlEngDOMImplementation class by calling its OpenL() method.

    Example:

    RXMlEngDOMImplementation impl;
    impl.OpenL();
    
    The RXMlEngDOMImplementation instance is the DOM Engine.
  3. Initialise the DOM parser by calling the RXmlEngDOMParser::Open() method on its instance.

    Example:

    RXmlEngDOMParser parser;
    parser.Open( impl );
    
    You can also have several parsers registered on a DOM Engine instance.
  4. Parse the specified XML file by calling the RXmlEngDOMParser::ParseFileL() method.

    Example:

    RXmlDocument myDoc = parser.ParseFileL( "tutorial.xml" );
    
    The myDoc object is a DOM tree containing the data from the XML file.
  5. Use the created DOM tree. For example, refer to the Searching a DOM Tree using XPath to search for specific elements or attributes in the DOM tree.
  6. Free your resources as necessary.
    1. Close the parser and the engine by calling their Close() functions.

      Example:

      parser.Close();
      impl.Close();
      
    2. Close the XML library by calling the XmlPopAndClose() method. This method also removes the serialisation resources from the clean-up stack.
    3. Perform any other clean-up operations.

Related tasks