xml - XML related utility classes

XML related utility classes.

util - Various utilities

XML utility classes and functions.

Requires at least Python 2.6. Simple import breaks on Python 2.5

class ContainerElementMixin(parent, root_tag, namespace='')[source]

Mixin class for container workalikes backed by a DOM.

__init__(parent, root_tag, namespace='')[source]
class MappingElement(parent, root_tag, namespace='')[source]

Provide a tag/text map for the children of the ‘root_tag’ descendent of ‘parent’. Given:


One could write:

mappingElement["key1"] == "value1"
__abstractmethods__ = frozenset([])
__init__(parent, root_tag, namespace='')[source]
__setitem__(key, value)[source]
class MappingElementIterator(element)[source]

Iterator over a ‘MappingElement’.

__abstractmethods__ = frozenset(['next'])
class Namespace(url='', element=None)[source]

Represent an XML namespace and provide several utility functions that help handle a document without namespace tags.

Element(tag, attrib={}, **extra)[source]
SubElement(parent, tag, attrib={}, **extra)[source]
__init__(url='', element=None)[source]
find(element, tag)[source]
findall(element, tag)[source]
findtext(element, tag, default=None)[source]
class QName(tag)[source]

Represent a qualified name

class SequenceElement(parent, root_tag, element_tag, namespace='', indent=' ')[source]

Provide a sequence of the values of the children tagged ‘element_tag’ of the ‘root_tag’ descendent of ‘parent’. Given:


One could write:

sequenceElement[1] == "value2"
__abstractmethods__ = frozenset([])
__init__(parent, root_tag, element_tag, namespace='', indent=' ')[source]
__setitem__(index, value)[source]
insert(index, value)[source]
class Writer(root_tag, attributes=None, tab_size=0)[source]

Pretty-print an XML tree.

__init__(root_tag, attributes=None, tab_size=0)[source]
write(node, where)[source]
make_property(elem, key=None)[source]

Create a property on the text of element ‘elem’ or, if the ‘key’ argument is given, on its ‘key’ attribute.


parse the ‘src’ XML file and return a DOM.