XmlExample: Using the XML framework to parse an XML file

Download

Click on the following link to download the example: XmlExample.zip

Click:browse to view the example code.

Introduction

This example application demonstrates the usage of the XML framework API to parse XML and WBXML files.

The overview contains the following sections:

Description

The example application demonstrates, how to use the XML framework to parse XML and WBXML files. It takes a valid XML file with a DTD (Document Type Declaration) definining its structure, and a WBXML (WAP Binary XML format) file as input. You can generate a WBXML file from an XML file using any freeware converters. The application's bld.inf file specifies the target path to which all the three files (XML, DTD, WBXML) need to be exported.

The application implements all the pure virtual functions of the Xml::MContentHandler class, which is a client interface to the XML framework. These functions inform the client application about the XML element being parsed, its content, parser errors if any and so on.

The XML and WBXML files are parsed using an object of the Xml::CParser class. The parser object is configured to report namespace mappings to the client application, using the function Xml::CParser::EnableFeature().

The application first opens a file session using RFs to read the XML and WBXML files. Then, the Xml::ParseL() function is called to start parsing the files. The application parses the XML file followed by the WBXML file. While these files are being parsed, status messages are printed to the console by the callback functions as and when they are invoked.

For demonstration purposes, the XML file is parsed twice, once by the Xml::CParser object created using the MIME type and again by the CParser object created using match data criteria. The match data criteria are specified using an object of the Xml::CMatchData class, which is passed to the Xml::CParser::NewLC() function while creating the parser object. This will return a CParser object that matches the specified MIME type, variant and so on.

Class summary

  • Xml::MContentHandler

  • Xml::RDocumentParameters

  • Xml::RAttributeArray

  • Xml::CMatchData

Build

The Symbian platform build process describes how to build an application.

The XmlExample builds an executable called xmlexample.exe in the standard location (\epoc32\release\winscw\<build_variant> for CodeWarrior). After launching the executable, depending on the emulator you are using, you may need to task away from the application launcher/shell screen to view the console.