Parsing XML DOM

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

Before you start, you must:


  1. Call the XmlEnginePushL() method to put parser resources on the clean-up stack.
            
             
            
            XmlEnginePushL();
           
  2. Initialise your instance of the 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 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 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 XmlPopAndClose() method. This method also removes the serialisation resources from the clean-up stack.

    3. Perform any other clean-up operations.