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 [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]XmlEnginePushL() method to put parser resources on the clean-up stack.
    XmlEnginePushL();
    
  2. Initialise your instance of the [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]RXmlEngDOMImplementation class by calling its OpenL() method.

    RXMlEngDOMImplementation impl;
    impl.OpenL();
    
    The RXMlEngDOMImplementation instance is the DOM Engine.
  3. Initialise the DOM parser by calling the [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]RXmlEngDOMParser::Open() method on its instance.
    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 [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]RXmlEngDOMParser::ParseFileL() method.
    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.

      parser.Close();
      impl.Close();
      
    2. Close the XML library by calling the [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]XmlPopAndClose() method. This method also removes the serialisation resources from the clean-up stack.
    3. Perform any other clean-up operations.

Related tasks