LxmlEventWriter

class xsdata.formats.dataclass.serializers.writers.LxmlEventWriter(config, output, ns_map=<factory>)[source]

XmlWriter implementation based on lxml package.

Based on the lxml.sax.ElementTreeContentHandler, converts sax events to an lxml ElementTree, serialize and write the result to the output stream. Despite that since it’s lxml it’s still pretty fast and has better support for special characters and encodings than native python.

Parameters
  • config (SerializerConfig) – Configuration instance

  • output (TextIO) – Output text stream

  • ns_map (Dict) – User defined namespace prefix-URI map

write(events)[source]

Iterate over the generator events and feed the sax content handler with the information needed to generate the xml output.

Example:

(XmlWriterEvent.START, "{http://www.w3.org/1999/xhtml}p"),
(XmlWriterEvent.ATTR, "class", "paragraph"),
(XmlWriterEvent.DATA, "Hello"),
(XmlWriterEvent.END, "{http://www.w3.org/1999/xhtml}p"),
Parameters

events (Generator) – Events generator