Generated XML Encode Functions

Generated C Function Format and Calling Parameters
Procedure for Calling C Encode Functions
Generated C++ Encode Method Format and Calling Parameters
Procedure for Using the C++ Control Class Encode Method

XML C encode and decode functions are generated when the -xml switch is specified on the command line. These are similar to the XER encode functions described earlier. Like XER, this function allows data in a populated variable to be formatted into an XML document. Unlike the XER variant, this function will produce XML that adheres more closely to the Worldwide Web Consortium (W3C) XML conventions. In particular, the following differences exist:

Also, if code is generated by compiling XML schema specifications, the generated XML will contain features defined in the schema which cannot be specified using plain ASN.1 such as attributes and namespaces. Note that it is possible to support these items if ASN.1 with Extended XER notation (E-XER) is used, but this is not supported by ASN1C. Its method of supporting these constructs is the direct compilation of XML schema files.

It is also important to note that the -xsd switch is complementary to the -xml switch when generating XML encoders and decoders. This is because the XML schema produced from the ASN.1 specification using the -xsd switch can be used to validate the XML messages generated using the XML encode functions. Similarly, an XML instance can be validated using the generated XML schema prior to decoding.

XML C encode functions are generated when the -xml switch is specified on the command line. For each ASN.1 production defined in the ASN.1 source file, a C XML encode function is generated. In the case of XML schema, a C encode function is generated for each type and global element declaration. This function will convert a populated C variable of the given type into an XML encoded message (i.e. an XML document).

If C++ code generation is specified, a control class is generated that contains an Encode method that wraps this function. This function is invoked through the class interface to encode an ASN.1 message into the variable referenced in the msgData component of the class.