For the XML encoding rules (XER), the generated class definition is as follows:
class ASN1C_<name> : public ASN1CType, ASN1XERSAXHandler { protected: ASN1T_<name>& msgData; ... additional control variables public: ASN1C_<name> (ASN1T_<name>& data); ASN1C_<name> ( ASN1MessageBufferIF& msgBuf, ASN1T_<name>& data); // standard encode/decode methods (defined in ASN1CType base class): // int Encode (); // int Decode (); // stream encode/decode methods: int EncodeTo (ASN1MessageBufferIF& msgBuf); int DecodeFrom (ASN1MessageBufferIF& msgBuf); // SAX Content Handler Interface virtual void startElement (const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs); virtual void characters (const XMLCh* const chars, const unsigned int length); virtual void endElement (const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname); } ;
The main differences between the BER/DER/PER control class definition and this are:
The class generated for XER inherits from the ASN1XERSAXHandler base class, and
The class implements the standard SAX content handler methods.
This allows an object of this class to be registered as a SAX content handler with any SAX-compliant XML parser. The parser would be used to read and parse XML documents. The methods generated by ASN1C would then receive the parsed data via the SAX interface and use the results to populate the data variables with the decoded data.
Note that for XML code generation (-xml command-line option), the SAX handler interface is not generated. That is because XML decoders use a pull-parser instead of SAX code to parse the XML input stream.