xsdata.codegen.mappers.schema module

class xsdata.codegen.mappers.schema.SchemaMapper[source]

Bases: object

Map a schema instance to classes, extensions and attributes.

classmethod map(schema)[source]

Map schema children elements to classes.

Parameters

schema (Schema) –

Return type

List[Class]

classmethod root_elements(schema)[source]

Return all valid schema elements that can be converted to classes.

Parameters

schema (Schema) –

classmethod build_class(obj, container, module, target_namespace)[source]

Build and return a class instance.

Parameters
Return type

Class

classmethod build_class_attributes(obj, target)[source]

Build the target class attributes from the given ElementBase children.

Parameters
classmethod build_class_extensions(obj, target)[source]

Build the item class extensions from the given ElementBase children.

Parameters
classmethod build_data_type(target, name, index=0, forward=False)[source]

Create an attribute type for the target class.

Parameters
Return type

AttrType

classmethod element_children(obj, restrictions)[source]

Recursively find and return all child elements that are qualified to be class attributes.

Parameters
Return type

Iterator[Tuple[ElementBase, Restrictions]]

classmethod element_namespace(obj, target_namespace)[source]

Return the target namespace for the given schema element.

In order:
  • elements/attributes with specific target namespace

  • prefixed elements returns the namespace from schema ns_map

  • qualified elements returns the schema target namespace

  • unqualified elements return an empty string

  • unqualified attributes return None

Parameters
Return type

Optional[str]

classmethod children_extensions(obj, target)[source]

Recursively find and return all target’s Extension classes.

If the initial given obj has a type attribute include it in result.

Parameters
Return type

Iterator[Extension]

classmethod build_class_extension(target, name, index, restrictions)[source]

Create an extension for the target class.

Parameters
  • target (Class) –

  • name (str) –

  • index (int) –

  • restrictions (Dict) –

Return type

Extension

classmethod build_class_attribute(target, obj, parent_restrictions)[source]

Generate and append an attribute field to the target class.

Parameters
classmethod build_class_attribute_types(target, obj)[source]

Convert real type and anonymous inner types to an attribute type list.

Parameters
Return type

List[AttrType]

classmethod build_inner_classes(obj, module, namespace)[source]

Find and convert anonymous types to a class instances.

Parameters
Return type

Iterator[Class]

classmethod is_class(item)[source]
Parameters

item (ElementBase) –

Return type

bool