Generated XER Decode Methods
The code generated to decode XML messages is different than that of the other encoding rules. This is because off-the-shelf XML parser software is used 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. ASN1C 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 for Java is the XERCES parser developed by the Apache Software Foundation (http://xml.apache.org). This is open source software and implementations of the parser are available for both C++ and Java. As mentioned, since SAX is a de-facto standard, it should be a relatively straightforward process to use the generated handlers with any other parser.
startElement characters endElementThe interface defines other methods that can be implemented as well, but these are sufficient to decode XER encoded data. These methods are added to an inner SAX handler class generated for each ASN.1 production.
The procedure to invoke the generated decode method is similar to that for the other encoding rules. It is as follows:
- Instantiate an XMLReader object. The XML parser interface should provide a factory method for creating an object of this type for any vendor-specific XML parser implementation.
- Instantiate a generated Java <ProdName> object to hold the decoded message data.
- Invoke the <ProdName> object decode method passing the reader created in step 1 and the URI of the XML document to be parsed. This method initiates and invokes the XML parser's parse method to parse the document. This, in turn, invokes the generated SAX handler methods.
- Methods within the <ProdName> object can now be used to access the decoded data. The member variables that were declared to be public can be accessed directly.
- Error handling is accomplished using a try-catch block to catch SAX exceptions.
Objective Systems, Inc.102 Pickering Way, Suite #506Exton, Pennsylvania 19341 http://www.obj-sys.com Phone: (484) 875-9841 Toll-free: (877) 307-6855 (US only) Fax: (484) 875-9830 info@obj-sys.com |