xsdata.builder module

class xsdata.builder.ClassBuilder(schema)[source]

Bases: object

schema: Schema = None
target_prefix: Optional[str] = None
build()[source]

Generate classes from schema elements.

Return type

List[Class]

build_class(obj)[source]

Build and return a class instance.

Return type

Class

build_class_attributes(obj, item)[source]

Build the target item class attributes from the given obj child elements.

If exists append default value attribute.

build_class_extensions(obj)[source]

Return a sorted, filtered list of extensions.

Return type

List[AttrType]

build_data_type(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]]

element_namespace(obj)[source]

Returns an element’s namespace by its prefix and form.

Examples:
  • 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]

element_extensions(obj, include_current=True)[source]

Recursively find and return all parent Extension classes.

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

Return type

Iterator[AttrType]

build_class_attribute(parent, obj)[source]

Generate and append an attribute instance to the parent class.

Raises

ValueError – if types list is empty

build_class_attribute_types(parent, obj)[source]

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

Return type

List[AttrType]

build_inner_class(obj)[source]

Convert anonymous type to class to be appended in the parent inner class list.

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(item)[source]
Return type

Optional[Attr]