XmlSerializer#
- class xsdata.formats.dataclass.serializers.XmlSerializer(config=<factory>, context=<factory>, writer=<class 'xsdata.formats.dataclass.serializers.writers.native.XmlEventWriter'>)[source]#
Xml serializer for data classes.
- Parameters:
config (
SerializerConfig
) – The serializer config instancecontext (
XmlContext
) – The models context instance
- writer#
alias of
XmlEventWriter
- write_dataclass(obj, namespace=None, qname=None, nillable=False, xsi_type=None)[source]#
Convert a model instance to sax events.
Optionally override the qualified name and the xsi attributes type and nil.
- write_xsi_type(value, var, namespace)[source]#
Convert a xsi:type value to sax events.
The value can be assigned to wildcard, element or compound fields
- write_value(value, var, namespace)[source]#
Convert any value to sax events according to the var instance.
The order of the checks is important as more than one condition can be true.
- write_list(values, var, namespace)[source]#
Convert an array of values to sax events.
- write_tokens(value, var, namespace)[source]#
Convert an array of token values to sax events.
- write_mixed_content(values, var, namespace)[source]#
Convert mixed content values to sax events.
- write_any_type(value, var, namespace)[source]#
Convert a value assigned to a xs:anyType field to sax events.
- write_any_element(value, var, namespace)[source]#
Convert a generic any element instance to sax events.
- xsi_type(var, value, namespace)[source]#
Return the xsi:type for the given value and field metadata instance.
If the value type is either a child or parent for one of the var types, we need to declare it as n xsi:type.
- write_elements(value, var, namespace)[source]#
Convert the value assigned to a compound field to sax events.
- write_choice(value, var, namespace)[source]#
Convert a single value assigned to a compound field to sax events.
- write_element(value, var, namespace)[source]#
Convert a value assigned to an element field to sax events.
- classmethod next_value(obj, meta)[source]#
Produce the next non attribute value of a model instance to convert.
The generator will produce the values in the order the fields are defined in the model or by their sequence number.
Sequential fields need to be rendered together in parallel order eg: <a1/><a2/><a1/><a/2></a1>
- classmethod next_attribute(obj, meta, nillable, xsi_type, ignore_optionals)[source]#
Produce the next attribute value to convert.
- Parameters:
- Yields:
An iterator of attribute name-value pairs.
- Return type:
- classmethod encode(value, var)[source]#
Encode a value 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.
- classmethod real_xsi_type(qname, target_qname)[source]#
Compare the qname with the target qname and return the real xsi:type.
- __eq__(other)#
Return self==value.
- __hash__ = None#