lxml
xsdata.formats.dataclass.serializers.writers.lxml
LxmlEventWriter
Bases: XmlWriter
Xml event writer based on lxml.sax.ElementTreeContentHandler
.
The writer converts the events to a lxml tree which is then converted to string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | SerializerConfig | The serializer config instance | required |
output | TextIO | The output stream to write the result | required |
ns_map | Dict | A user defined namespace prefix-URI map | required |
Attributes:
Name | Type | Description |
---|---|---|
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 |
Source code in xsdata/formats/dataclass/serializers/writers/lxml.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
build_handler()
Build the content handler instance.
Returns:
Type | Description |
---|---|
ElementTreeContentHandler | An element tree content handler instance. |
Source code in xsdata/formats/dataclass/serializers/writers/lxml.py
30 31 32 33 34 35 36 |
|
write(events)
Feed the sax content handler with events.
The receiver will also add additional root attributes like xsi or no namespace location. In the end convert the handler etree to string based on the configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events | Iterator | An iterator of sax events | required |
Raises:
Type | Description |
---|---|
XmlWriterError | On unknown events. |
Source code in xsdata/formats/dataclass/serializers/writers/lxml.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
LxmlTreeBuilder
Bases: EventContentHandler
Source code in xsdata/formats/dataclass/serializers/writers/lxml.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
build_handler()
Build the content handler instance.
Returns:
Type | Description |
---|---|
ElementTreeContentHandler | An element tree content handler instance. |
Source code in xsdata/formats/dataclass/serializers/writers/lxml.py
71 72 73 74 75 76 77 |
|
build(events)
Feed the sax content handler with events.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events | Iterator | An iterator of sax events | required |
Raises:
Type | Description |
---|---|
XmlWriterError | On unknown events. |
Returns:
Type | Description |
---|---|
ElementTree | The element tree instance. |
Source code in xsdata/formats/dataclass/serializers/writers/lxml.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|