XmlVar#

class xsdata.formats.dataclass.models.elements.XmlVar(index, name, qname, types, clazz, init, mixed, factory, tokens_factory, format, derived, any_type, process_contents, required, nillable, sequence, default, xml_type, namespaces, elements, wildcards, wrapper=None, **kwargs)[source]#

Class field binding metadata.

Parameters:
  • index (int) – Position index of the variable

  • name (str) – Name of the variable

  • qname (str) – Namespace-qualified name of the variable

  • types (Sequence[Type]) – Supported types for the variable

  • clazz (Optional[Type]) – Target class type

  • init (bool) – Indicates if the field should be included in the constructor

  • mixed (bool) – Indicates if the field supports mixed content type values.

  • factory (Optional[Callable]) – Callable factory for lists

  • tokens_factory (Optional[Callable]) – Callable factory for tokens

  • format (Optional[str]) – Information about the value format

  • derived (bool) – Indicates whether parsed values should be wrapped with a generic type

  • any_type (bool) – Indicates if the field supports dynamic value types

  • process_contents (str) – Information about processing contents

  • required (bool) – Indicates if the field is mandatory

  • nillable (bool) – Indicates if the field supports nillable content

  • sequence (Optional[int]) – Specifies rendering values in sequential mode

  • default (Any) – Default value or factory for the field

  • xml_type (str) – Type of the XML field (element, attribute, etc.)

  • namespaces (Sequence[str]) – List of supported namespaces

  • elements (Mapping[str, XmlVar]) – Mapping of qualified name-repeatable elements

  • wildcards (Sequence[XmlVar]) – List of repeatable wildcards

  • wrapper (Optional[str]) – Name for the wrapper (applies for list types only)

tokens#

Indicates if the field has associated tokens

list_element#

Indicates if the field is a list or tuple element

namespace_matches#

Matching namespaces information

is_clazz_union#

Indicates if the field is a union of multiple types

local_name#

Local name extracted from the qualified name

is_text#

Indicates if the field represents text content

is_element#

Indicates if the field represents an XML element

is_elements#

Indicates if the field represents a sequence of XML elements

is_wildcard#

Indicates if the field represents a wildcard

is_attribute#

Indicates if the field represents an XML attribute

is_attributes#

Indicates if the field represents a sequence of XML attributes

property element_types: Set[Type]#

Return the unique element types.

find_choice(qname)[source]#

Match and return a choice field by its qualified name.

Parameters:

qname (str) – The qualified name to lookup

Return type:

Optional[XmlVar]

Returns:

The choice xml var instance or None if there are no matches.

find_value_choice(value, is_class)[source]#

Match and return a choice field that matches the given value.

Cases:
  • value is none or empty tokens list: look for a nillable choice

  • value is a dataclass: look for exact type or a subclass

  • value is primitive: test value against the converter

Parameters:
  • value (Any) – The value to match its type to one of the choices

  • is_class (bool) – Whether the value is a binding class

Return type:

Optional[XmlVar]

Returns:

The choice xml var instance or None if there are no matches.

find_nillable_choice(is_tokens)[source]#

Find the first nillable choice.

Parameters:

is_tokens (bool) – Specify if the choice must support token values

Return type:

Optional[XmlVar]

Returns:

The choice xml var instance or None if there are no matches.

find_clazz_choice(clazz)[source]#

Find the best matching choice for the given class.

Best Matches:
  1. The class is explicitly defined in a choice types

  2. The class is a subclass of one of the choice types

Parameters:

clazz (Type) – The class type to match

Return type:

Optional[XmlVar]

Returns:

The choice xml var instance or None if there are no matches.

find_primitive_choice(value, is_tokens)[source]#

Match and return a choice field that matches the given primitive value.

Parameters:
  • value (Any) – A primitive value, e.g. str, int, float, enum

  • is_tokens (bool) – Specify whether it’s a tokens value

Return type:

Optional[XmlVar]

Returns:

The choice xml var instance or None if there are no matches.

is_optional(value)[source]#

Verify this var is optional and the value matches the default one.

Parameters:

value (Any) – The value to compare against the default one

Return type:

bool

Returns:

The bool result.

match_namespace(qname)[source]#

Match the given qname to the wildcard allowed namespaces.

Parameters:

qname (str) – The namespace qualified name of an element

Return type:

bool

Returns:

The bool result.

__eq__(other)#

Implement equality operator.

Return type:

bool

__hash__ = None#
__iter__()#

Implement iteration.

Return type:

Iterator