PyXB’s content model is used to complete the link between the Component Model and the Binding Model. These classes are the ones that:
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.
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:
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.
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.
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.
The relations among the classes defining the content model are displayed in the following diagram.
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.