SimplerXMLGenerator
This class extends the standard XML generator to provide a more robust and deterministic way of creating XML documents. It features a convenience method for adding simple elements, ensures deterministic output by sorting attributes, and enforces XML 1.0 compliance by preventing the serialization of unsupported control characters.
Methods
addQuickElement()
@classmethod
def addQuickElement(
name: string,
contents: string = None,
attrs: dict = None
)
Convenience method for adding an element with no children
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The XML tag name for the element to be created |
| contents | string = None | The text content to be placed inside the element; if None, the element will be empty |
| attrs | dict = None | A dictionary of attribute names and values to be applied to the element |
characters()
@classmethod
def characters(
content: string
)
Writes character data to the XML output after validating that it contains no illegal control characters.
Parameters
| Name | Type | Description |
|---|---|---|
| content | string | The text content to be written to the XML stream |
startElement()
@classmethod
def startElement(
name: string,
attrs: dict
)
Signals the start of an XML element and ensures that attributes are written in a deterministic, sorted order.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The name of the XML element being started |
| attrs | dict | A dictionary of attributes to be included in the element tag |