XML document cannot be transformed into ASN.1 DER-encoded data

If the XML file has incorrect content, for example, malformed XML or an XML document that does not fit to the ASN.1 specification, the asn1-data-from-xml command line tool provides a general error message that the file cannot be converted.

For example:


/tmp/WRON7BYqPk/xml2asn: input file 'data/02_orders.xml' cannot be converted
asn1-data-from-xml: test data generation failed
asn1-data-from-xml: test data generator failed using the system command '/tmp/WRON7BYqPk/xml2asn data/02_orders.xml'

The reason for such an output might be, for example, the following sample XML document that shows the wrong closing tag </Orde>. The valid closing tag is </Order>.


<Sample>
	<orders>
		<Order>
			<count>20</count>
			<color><red/></color>
			<ordered>20131224150000Z</ordered>
		</Orde>
		<Order>
			<size><a5/></size>
			<count>70</count>
			<ordered>20131224153000Z</ordered>
		</Orde>
	</orders>
</Sample>

The ASN.1 decoder and encoder in the /tmp/WRON7BYqPK directory is only temporarily available. The asn1-data-from-xml command line tool ensures that this temporary helper is removed automatically.

If you follow all the rules that are described in the context of the ASN1Encode operator, but your XML document cannot be translated, you can try to debug the XML decoder using the -verbose option, for example:


asn1-data-from-xml -grammar etc/grammar.asn -output data/input.bin data/02_orders.xml -verbose

The following reduced sample output shows the source of the problem:


XER/SEQUENCE: tcv = 1, ph=0 [Sample] (constr_SEQUENCE.c:712)
...
Unexpected XML tag in SEQUENCE [</Orde] (constr_SEQUENCE.c:844)
/tmp/9ayRmInp3a/xml2asn: input file 'data/02_orders.xml' cannot be converted
asn1-data-from-xml: test data generation failed
asn1-data-from-xml: test data generator failed using the system command '/tmp/9ayRmInp3a/xml2asn data/02_orders.xml'