Content Model

PyXB’s content model is used to complete the link between the Component Model and the Binding Model. These classes are the ones that:

  • determine what Python class attribute is used to store which XML element or attribute;
  • distinguish those elements that can occur at most once from those that require an aggregation; and
  • ensure that the ordering and occurrence constraints imposed by the XML model group are satisfied, when XML is converted to Python instances and vice-versa.

Associating XML and Python Objects

The classes involved in the content model are in the pyxb.binding.content module. Their relationships to binding classes are displayed in the following diagram.

_images/ContentBindingRelations.jpg

In the standard code generation template, both element and attribute values are stored in Python class fields. As noted in Deconflicting Names it is necessary to ensure an attribute and an element which have the same name in their containing complex type have distinct names in the Python class corresponding to that type. Use information for each of these is maintained in the type class. This use information comprises:

  • the original name of the element/attribute in the XML
  • its deconflicted name in Python
  • the private name by which the value is stored in the Python instance dictionary

Other information is specific to the type of use. The complexTypeDefinition retains maps from the component’s name the attribute use or element use instance corresponding to the component’s use.

Attribute Uses

The information associated with an attribute use is recorded in an AttributeUse instance. This class provides:

A map is used to map from expanded names to AttributeUse instances. This map is defined within the class definition itself.

Element Uses

The element analog to an attribute use is an element declaration, and the corresponding information is stored in a ElementUse instance. This class provides:

A map is used to map from expanded names to ElementUse instances. This map is defined within the class definition itself.

Content Model Description

The relations among the classes defining the content model are displayed in the following diagram.

_images/ContentModel.jpg

Each complex type binding class has a _ContentModel which defines constraints on the content of an instance of the class. The content model includes occurrence constraints and information on subterms, which either XML model groups or element uses.

See the validation method for details on how all this really works.

Table Of Contents

Previous topic

Binding Model

Next topic

User Reference

This Page