xsdata.parser module

class xsdata.parser.SchemaParser(name_generator=<function camel_case>, cache=<factory>, index=<factory>, target_namespace=None, default_attributes=None, default_open_content=None, schema_location=None)[source]

Bases: xsdata.formats.dataclass.parsers.xml.XmlParser

A simple parser to convert an xsd schema to an easy to handle data structure based on dataclasses.

The parser is a dummy as possible but it will try to normalize certain things like apply parent properties to children.

element_form: Optional[xsdata.models.enums.FormType] = None
attribute_form: Optional[xsdata.models.enums.FormType] = None
target_namespace: Optional[str] = None
default_attributes: Optional[str] = None
default_open_content: Optional[xsdata.models.elements.DefaultOpenContent] = None
schema_location: Optional[pathlib.Path] = None
name_generator()
Return type

str

from_xsd_string(source)[source]
Return type

Schema

from_xsd_path(path)[source]
Return type

Schema

dequeue_node(element)[source]

Override parent method to skip empty elements and to set the object index.

Return type

Optional[~T]

start_schema(element, item)[source]

Collect the schema’s default form for attributes and elements for later usage.

set_schema_forms(obj)[source]

Set the default form type for elements and attributes.

Global elements and attributes are by default qualified.

set_schema_namespaces(obj, element)[source]

Set the given schema’s target namespace and add the default namespaces if the are missing xsi, xlink, xml, xs.

static set_namespace_map(element, obj)[source]
static add_default_imports(obj)[source]

Add missing imports to the standard schemas if the namespace is declared and.

resolve_schemas_locations(obj)[source]

Resolve the locations of the schema overrides, redefines, includes and imports relatively to the schema location.

resolve_path(location)[source]

Resolve the given location string relatively the schema location path.

Return type

Optional[Path]

resolve_local_path(location, namespace)[source]

Resolve the given namespace to one of the local standard schemas or fallback to the external file path.

end_attribute(obj, element)[source]

Assign the schema’s default form for attributes if the given attribute form is None.

end_complex_type(obj, element)[source]

Prepend an attribute group reference when default attributes apply.

end_default_open_content(obj, element)[source]
end_element(obj, element)[source]

Assign the schema’s default form for elements if the given element form is None.

end_extension(obj, element)[source]
classmethod end_open_content(obj, element)[source]
end_restriction(obj, element)[source]
end_schema(obj, element)[source]

Normalize various properties for the schema and it’s children.

classmethod parse_value(types, value, default=None)[source]

Convert xml string values to s python primitive type.

Return type

Any