SAX Based Decode Methods

If -sax is specified on the XBinder command-line, the code generated to decode XML messages uses off-the-shelf XML parser software to parse the XML documents to be decoded. This software contains a common interface known as the Simple API for XML (or SAX) that is a de-facto standard that is supported by most parsers. XBinder generates an implementation of the content handler interface defined by this standard. This implementation receives the parsed XML data and uses it to populate the structures generated by the compiler.

The default XML parser used is the GNOME LibXML2 parser (http://xmlsoft.org). This is a full-featured, open-source parser that was implemented in C. XBinder generates C++ SAX handler classes within the generated type class for a given XML schema type. The methods within these classes are called from the SAX interface of the XML parser framework to decode XML data into the generated typed data structures. The interface was designed to be generic so that other XML parsers could be easily substituted.

In addition to LibXML2, interfaces to the following other C/C++ XML parsers are also available:

1. EXPAT parser (http://www.expat.org)

2. XERCES C++ parser (http://apache.org)

3. A custom micro-SAX parser. This is a bare-boned XML parser targeted at small footprint applications.

Interfacing to other parsers requires building an abstraction layer to map the common interface to the vendor’s interface.

XBinder generates code to implement the following SAX content handler methods:

       startElement

       characters

       endElement

The interface defines other methods that can be implemented as well, but these are sufficient to decode XML encoded data.