# XmlContext

class xsdata.formats.dataclass.context.XmlContext(element_name_generator=<function return_input>, attribute_name_generator=<function return_input>, class_type='dataclasses', models_package=None)

  The service provider for binding operations’ metadata.

  Parameters:

    - element_name_generator (`Callable`) – Default element name generator

    - attribute_name_generator (`Callable`) – Default attribute name generator

    - class_type (`str`) – Default class type dataclasses

    - models_package (`Optional`[`str`]) – Restrict auto locate to a specific package

  fetch(clazz, parent_ns=None, xsi_type=None)

    Fetch the model metadata of the given dataclass type, namespace and xsi type.

    Parameters:

      - clazz (`Type`) – The requested dataclass type

      - parent_ns (`Optional`[`str`]) – The inherited parent namespace

      - xsi_type (`Optional`[`str`]) – if present it means that the given clazz is derived and the lookup procedure needs to check and match a dataclass model to the qualified name instead

    Return type:

      `XmlMeta`

  build_xsi_cache()

    Index all imported dataclasses by their xsi:type qualified name.

  find_types(qname)

    Find all classes that match the given xsi:type qname.

    - Ignores native schema types, xs:string, xs:float, xs:int, …

    - Rebuild cache if new modules were imported since last run

    Parameters:

      qname (`str`) – Qualified name

    Return type:

      `List`[`Type`[`TypeVar`(`T`)]]

  find_type(qname)

    Return the most recently imported class that matches the given xsi:type qname.

    Parameters:

      qname (`str`) – Qualified name

    Return type:

      `Optional`[`Type`[`TypeVar`(`T`)]]

  find_type_by_fields(field_names)

    Find a dataclass from all the imported modules that matches the given list of field names.

    Parameters:

      field_names (`Set`[`str`]) – A unique list of field names

    Return type:

      `Optional`[`Type`[`TypeVar`(`T`)]]

  find_subclass(clazz, qname)

    Compare all classes that match the given xsi:type qname and return the first one that is either a subclass or shares the same parent class as the original class.

    Parameters:

      - clazz (`Type`) – The search dataclass type

      - qname (`str`) – Qualified name

    Return type:

      `Optional`[`Type`]

  build(clazz, parent_ns=None, globalns=None)

    Fetch from cache or build the binding metadata for the given class and parent namespace.

    Parameters:

      - clazz (`Type`) – A dataclass type

      - parent_ns (`Optional`[`str`]) – The inherited parent namespace

    Return type:

      `XmlMeta`

  build_recursive(clazz, parent_ns=None)

    Build the binding metadata for the given class and all of its dependencies.

  classmethod is_derived(obj, clazz)

    Return whether the given obj is derived from the given dataclass type.

    Parameters:

      - obj (`Any`) – A dataclass instance

      - clazz (`Type`) – A dataclass type

    Return type:

      `bool`