The ASN.1-to-XSD translation capability is available in both the ASN1C compiler and in a separate tool named ASN2XSD. To generate XSD code using ASN1C, add -xsd to the ASN1C command-line or check the box in the ASN1C GUI wizard for generating an equivalent XSD file. The same result can be obtained by running ASN2XSD directly. In both cases, options are available for customizing the generated XSD code. These are summarized below for the ASN2XSD executable, but the same options can be used with ASN1C.
To test if ASN2XSD was successfully installed, enter asn2xsd with no parameters as follows (note: if you have not updated your PATH variable, you will need to enter the full pathname):
asn2xsd
You should observe the following display (or something similar):
ASN2XSD, Version 6.4.x ASN.1 to XSD translation tool Copyright (c) 2003-2011 Objective Systems, Inc. All Rights Reserved. Usage: asn2xsd <filename> options <filename> ASN.1 source file name options: -warnings Output compiler warning messages -o <directory> Output file directory -I <directory> Import file directory -list Generate listing -appinfo [<items>] Generate appInfo for ASN.1 items <items> can be tags, enum, and/or ext ex: -appinfo tags,enum,ext default = all if <items> not given -attrs [<items>] Generate non-native attributes for <items> <items> is same as for -appinfo -targetns [<namespace>] Specify target namespace <namespace> is namespace URI, if not given no target namespace declaration is added -tables Generate XSD code for table constraints -stdout Output code to stdout -xer Generate XSD code corresponding to XER encoding
To use ASN2XSD, at a minimum, an ASN.1 source file must be provided. The source file specification can be a full pathname or only what is necessary to qualify the file. If directory information is not provided, the user's current default directory is assumed. If a file extension is not provided, the default extension ".asn" is appended to the name. Multiple source filenames may be specified on the command line to compile a set of files. The wildcard characters `*' and `%' are also allowed in source filenames (for example, the command `asn2xsd *.asn' will compile all ASN.1 files in the current working directory).
The source file(s) must contain ASN.1 productions that define ASN.1 types and/or value specifications. This file must strictly adhere to the syntax specified in ASN.1 standard ITU X.680.. The deprecated X.208 standard is not supported in ASN2XSD although the ANY type from that standard is recognized.
The following table lists all of the command line options related to ASN.1 to XSD translation.
Option | Argument | Description |
---|---|---|
-appInfo | tags enum ext | This option instructs asn2xsd to generate an <appinfo> section within the generated XSD file that contains additional ASN.1 specific information. This includes information about tags, enumerated types, or extension types. The argument is optional - if no argument is given information is generated for all of these items. It is also possible to specify multiple items by using a comma-separated list (for example, -appInfo tags,enum). |
-attrs | tags enum ext | This option instructs asn2xsd to generate non-native attributes for elements within the generated XSD file that contain additional ASN.1 specific information. This includes information about tags, enumerated types, or extension types. The argument is optional - if no argument is given information is generated for all of these items. It is also possible to specify multiple items by using a comma-separated list (for example, -appInfo tags,enum). |
-tables | <filename> | This option is used to generate additional code for the handling of table constraints as defined in the X.682 standard. See the Generated Information Object Table Structures section for additional details on the type of code generated to support table constraints. |
-I | <directory> | This option is used to specify a directory that the compiler will search for ASN.1 source files for IMPORT items. Multiple -I qualifiers can be used to specify multiple directories to search. |
-list | None | Generate listing. This will dump the source code to the standard output device as it is parsed. This can be useful for finding parse errors |
-o | <directory> | This option is used to specify the name of a directoryto which all of the generated files will be written. |
-pdu | <typeName> | Designate given type name to be a "Protocol Definition Unit" (PDU) type. This will cause a C++ control class to be generated for the given type. By default, PDU types are determined to be types that are not referenced by any other types within a module. This option allows that behavior to be overridden. The `*' wildcard character may be specified for <typeName> to indicate that all productions within an ASN.1 module should be treated as PDU types. |
-targetns | <URI> | Specify URI for target namespace to be added to the generated XSD code. If this option is omitted, no target namespace declaration is added. |
-warnings | None | Output information on compiler generated warnings. |
-xer | None | Generate a schema corresponding to the XER encoding of the ASN.1 |