# Component Model

PyXB’s component model is the representation of XML schema components as a complex relation of data objects. Each object class corresponds to one of the thirteen XML Schema Components, and names of components and their properties follow those definitions. All classes specific to the component model are found in the `pyxb.xmlschema.structures` module.

The relationships amongst components is depicted in the following diagram. Composite aggregation generally denotes ownership and shared aggregation reference, but don’t look for consistency.

## Component Model Mix-ins

A variety of Mix-in classes are used to allow common code to be abstracted or to mark objects as having certain capabilities. These mixins are:

- `pyxb.xmlschema.structures._SchemaComponent_mixin` marks the object as being a schema component and holds its `pyxb.namespace.NamespaceContext`. It also records relations between components in a global definition and their clones where those definitions are expanded.
- `pyxb.xmlschema.structures._Singleton_mixin` is used to ensure there is only one instance each of the simple ur-type and ur-type. It overloads `__new__` to ensure that only one instance of the class is ever constructed.
- `pyxb.xmlschema.structures._Annotated_mixin` provides the support for all components that contain an annotation as a child element.
- `pyxb.xmlschema.structures._NamedComponent_mixin` supports components that can be identified by name. This includes the target namespace (which may be anonymous) if the component is global, and the complex type definition that serves as the component’s scope when it is local.
- `pyxb.xmlschema.structures._ValueConstraint_mixin` provides support for components that have value constraints : that is, provide a default value and optionally require a fixed value.
- `pyxb.xmlschema.structures._ScopedDeclaration_mixin` is used by element declarations and complex type definitions which may be named but only referenceable within a specific scope.
- `pyxb.xmlschema.structures._AttributeWildcard_mixin` provides support for attribute group definitions and complex type definitions, both of which allow wildcard attributes.

## Other Information

Most of the important information about the component model is best obtained from the specification or from the `PyXB component model API`. Tidbits of other relevant information:

- An understanding of Namespace Resolution is important.
- Element and attribute declarations that are incorporated by reference are represented in local scope by a copy of the global declaration. This aids in the infrastructure that binds declarations from model and attribute groups to a specific context. Local declarations are associated only with the complex type in which they appear; types that extend or restrict that type refer to the declaration instance associated with the base type.
- PyXB strictly enforces the requirement that multiple element declarations within a complex type be compatible with respect to type and other attributes. Since occurrence restrictions are associated with a Particle instance rather than the declaration, the same element can appear in multiple places with different multiplicities. Note, though, that the default code generation module collapses all occurrences of any given element into a single Python field in the binding.