Skip to main content

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

NameTypeDescription
namestringThe XML tag name for the element to be created
contentsstring = NoneThe text content to be placed inside the element; if None, the element will be empty
attrsdict = NoneA 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

NameTypeDescription
contentstringThe 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

NameTypeDescription
namestringThe name of the XML element being started
attrsdictA dictionary of attributes to be included in the element tag