XmlEventWriter#
- class xsdata.formats.dataclass.serializers.writers.XmlEventWriter(config, output, ns_map)[source]#
Xml event writer based on xml.sax.saxutils.XMLGenerator.
The writer converts sax events directly to xml output without storing any intermediate results in memory.
- Parameters:
config (
SerializerConfig
) – The serializer config instanceoutput (
TextIO
) – The output stream to write the resultns_map (
Dict
) – A user defined namespace prefix-URI map
- handler#
The content handler instance
- in_tail#
Specifies whether the text content has been written
- tail#
The current element tail content
- attrs#
The current element attributes
- ns_context#
The namespace context queue
- pending_tag#
The pending element namespace, name tuple
- pending_prefixes#
The pending element namespace prefixes
- build_handler()[source]#
Build the content handler instance.
- Return type:
- Returns:
A xml generator content handler instance.
- start_tag(qname)[source]#
Start tag notification receiver.
The receiver will flush the start of any pending element, create new namespaces context and queue the current tag for generation.
The receiver will also write the necessary whitespace if pretty print is enabled.
- Parameters:
qname (
str
) – The qualified name of the starting element
- end_tag(qname)[source]#
End tag notification receiver.
The receiver will flush if pending the start of the element, end the element, its tail content and its namespaces prefix mapping and current context.
The receiver will also write the necessary whitespace if pretty print is enabled.
- Parameters:
qname (
str
) – The qualified name of the element
- add_attribute(qname, value, root=False)#
Add attribute notification receiver.
The receiver will convert the key to a namespace, name tuple and convert the value to string. Internally the converter will also generate any missing namespace prefixes.
- add_namespace(uri)#
Add the given uri to the current namespace context.
If the uri empty or a prefix already exists, skip silently.
- encode_data(data)#
Encode data for xml rendering.
- flush_start(is_nil=True)#
Flush start notification receiver.
The receiver will pop the xsi:nil attribute if the element is not empty, prepare and send the namespace prefix-URI map and the element with its attributes to the content handler for generation.
- Parameters:
is_nil (
bool
) – Specify if the element requires xsi:nil=”true” when content is empty
- classmethod is_xsi_type(qname, value)#
Return whether the value is a xsi:type.
- reset_default_namespace()#
Reset the default namespace if the pending element is not qualified.
- set_data(data)#
Set data notification receiver.
The receiver will convert the data to string, flush any previous pending start element and send it to the handler for generation.
If the text content of the tag has already been generated then treat the current data as element tail content and queue it to be generated when the tag ends.
- Parameters:
data (
Any
) – The element text or tail content
- start_document()#
Start document notification receiver.
Write the xml version and encoding, if the configuration is enabled.
- start_namespaces()#
Send the current namespace prefix-URI map to the content handler.
Save the list of prefixes to be removed at the end of the current pending tag.
- write(events)#
Feed the sax content handler with events.
The receiver will also add additional root attributes like xsi or no namespace location.