Mapping to XML

This section explains how struct specifications (which are instances of the struct DTD) can be converted to XML DTDs that can validate data structures serialized as XML. An important feature of the programming language mappings is to read and write native data structures of the programming language from and to XML.

The following mapping rules apply:

  • A vfield is mapped to an XML element with the same name as the field. The field value is in the text content of the element, formatted according to the datatype mapping rules described in Data types.

  • A gfield is mapped to an XML element with the same name as the field. The content-model of the element is the same as the content model of the struct itself.

  • List fields (vlfield and glfield) are mapped to an XML element with the same name as the field, suffixed by -list. Each item in the list is mapped to an element with the same name as the field.

  • When a struct is serialized, the element name is the name of the struct class.

    The content model is a sequence, where optional fields are marked as such. The order of the elements in the sequence is the same as in the struct specification.

    Note that conceptually fields are unordered, but for compatibility with XML 1.0 parsers, the field order must be preserved.

  • When a list of structs is serialized, the element name is the name of the struct class, suffixed by -list, and containing elements with the name of the struct class.

Note

The python script struct2dtd.py is used to produce XML DTDs from struct instances.

Examples

The following is the DTD produced from the above StructExample.xml.

Click here to show/download StructExample.dtd.txt.

The following is the DTD produced from the above StructExampleBase.xml.

Click here to show/download StructExampleBase.dtd.txt.