xsdata.builder module

class xsdata.builder.ClassBuilder(schema, redefine=None)[source]

Bases: object

schema: Schema = None
redefine: Optional[xsdata.models.elements.Redefine] = None
target_prefix: Optional[str] = None
build()[source]

Generate classes from schema and redefined elements.

Return type

List[Class]

build_class(obj)[source]

Build and return a class instance.

Return type

Class

build_class_attributes(obj, instance)[source]

Build the instance class attributes from the given ElementBase children.

build_class_extensions(obj, instance)[source]

Build the item class extensions from the given ElementBase children.

build_data_type(instance, name, index=0, forward_ref=False)[source]
Return type

AttrType

element_children(obj)[source]

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

Return type

Iterator[Union[Attribute, Element, Restriction, Enumeration, Union, List, SimpleType]]

element_namespace(obj)[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 nsmap

  • qualified elements returns the schema target namespace

  • unqualified elements return an empty string

  • unqualified attributes return None

Return type

Optional[str]

children_extensions(obj, instance)[source]

Recursively find and return all instance’s Extension classes.

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

Return type

Iterator[Extension]

build_class_extension(instance, name, index, restrictions)[source]
build_class_attribute(instance, obj)[source]

Generate and append an attribute instance to the instance class.

Raises

ValueError – if types list is empty

build_class_attribute_types(instance, obj)[source]

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

Return type

List[AttrType]

build_inner_class(obj)[source]

Find and convert anonymous types to a class instance.

Return type

Optional[Class]

static has_anonymous_class(obj)[source]

Check if the attribute element contains anonymous complex type.

Return type

bool

static has_anonymous_enumeration(obj)[source]

Check if the attribute element contains anonymous restriction with enumeration facet.

Return type

bool

static default_class_attribute(instance)[source]
Return type

Optional[Attr]