# XmlSerializer

class xsdata.formats.dataclass.serializers.XmlSerializer(config=<factory>, context=<factory>, writer=<class 'xsdata.formats.dataclass.serializers.writers.lxml.LxmlEventWriter'>)

  Xml serializer for dataclasses.

  Parameters

    - config (`SerializerConfig`) – Serializer configuration

    - context (`XmlContext`) – Model context provider

    - writer (`Type`[`XmlWriter`]) – Override default XmlWriter

  writer

    alias of `xsdata.formats.dataclass.serializers.writers.lxml.LxmlEventWriter`

  render(obj, ns_map=None)

    Convert and return the given object tree as xml string.

    Parameters

      - obj (`Any`) – The input dataclass instance

      - ns_map (`Optional`[`Dict`, `None`]) – User defined namespace prefix-URI map

    Return type

      `str`

  write(out, obj, ns_map=None)

    Write the given object tree to the output text stream.

    Parameters

      - out (`TextIO`) – The output stream

      - obj (`Any`) – The input dataclass instance

      - ns_map (`Optional`[`Dict`, `None`]) – User defined namespace prefix-URI map

  write_object(obj)

    Produce an events stream from a dataclass or a derived element.

  write_dataclass(obj, namespace=None, qname=None, nillable=False, xsi_type=None)

    Produce an events stream from a dataclass.

    Optionally override the qualified name and the xsi properties type and nil.

    Return type

      `Generator`

  write_xsi_type(value, var, namespace)

    Produce an events stream from a dataclass for the given var with with xsi abstract type check for non wildcards.

    Return type

      `Generator`

  write_value(value, var, namespace)

    Delegates the given value to the correct writer according to the variable metadata.

    The order of the checks is important as more than one condition can be true.

    Return type

      `Generator`

  write_list(values, var, namespace)

    Produce an events stream for the given list of values.

    Return type

      `Generator`

  write_tokens(value, var, namespace)

    Produce an events stream for the given tokens list or list of tokens lists.

    Return type

      `Generator`

  write_mixed_content(values, var, namespace)

    Produce an events stream for the given list of mixed type objects.

    Return type

      `Generator`

  write_any_type(value, var, namespace)

    Produce an events stream for the given object.

    The object can be a dataclass or a generic object or any other simple type.

    Return type

      `Generator`

  write_wildcard(value, var, namespace)

    Produce an element events stream for the given generic object.

    Return type

      `Generator`

  xsi_type(var, value, namespace)

    Get xsi:type if the given value is a derived instance.

    Return type

      `Optional`[`str`, `None`]

  write_elements(value, var, namespace)

    Produce an events stream from compound elements field.

    Return type

      `Generator`

  write_choice(value, var, namespace)

    Produce an events stream for the given value of a compound elements field.

    The value can be anything as long as we can match the qualified name or its type to a choice.

    Return type

      `Generator`

  write_element(value, var, namespace)

    Produce an element events stream for the given simple type value.

    Return type

      `Generator`

  classmethod write_data(value, var, namespace)

    Produce a data event for the given value.

    Return type

      `Generator`

  classmethod next_value(obj, meta)

    Return the non attribute variables with their object values in the correct order according to their definition and the sequential metadata property.

    Sequential fields need to be rendered together in parallel order eg: <a1/><a2/><a1/><a/2></a1>

    Return type

      `Iterator`[`Tuple`[`XmlVar`, `Any`]]

  classmethod next_attribute(obj, meta, nillable, xsi_type, ignore_optionals)

    Return the attribute variables with their object values if set and not empty iterables.

    Parameters

      - obj (`Any`) – Input object

      - meta (`XmlMeta`) – Object metadata

      - nillable (`bool`) – Is model nillable

      - xsi_type (`Optional`[`str`, `None`]) – The true xsi:type of the object

      - ignore_optionals (`bool`) – Skip optional attributes with default value

    Return type

      `Iterator`[`Tuple`[`str`, `Any`]]

    Returns

  classmethod encode(value, var)

    Encode values for xml serialization.

    Converts values to strings. QName instances is an exception, those values need to wait until the XmlWriter assigns prefixes to namespaces per element node. Enums and Tokens may contain QName(s) so they also get a special treatment.

    We can’t do all the conversions in the writer because we would need to carry the xml vars inside the writer. Instead of that we do the easy encoding here and leave the qualified names for later.

    Return type

      `Any`

  __eq__(other)

    Return self==value.

  __hash__ = None