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]

x.__init__(…) initializes x; see help(type(x)) for signature

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

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

<parent>
    <root_tag>
        <key1>value1</key1>
        <key2>value2</key2>
    </root_tag>
</parent>

One could write:

mappingElement["key1"] == "value1"
__abstractmethods__ = frozenset([])
__delitem__(key)[source]
__getitem__(key)[source]
__init__(parent, root_tag, namespace='')[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__iter__()[source]
__setitem__(key, value)[source]
class MappingElementIterator(element)[source]

Iterator over a ‘MappingElement’.

__abstractmethods__ = frozenset(['next'])
__init__(element)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__next__()[source]
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]

x.__init__(…) initializes x; see help(type(x)) for signature

find(element, tag)[source]
findall(element, tag)[source]
findtext(element, tag, default=None)[source]
get_tag(element)[source]
class QName(tag)[source]

Represent a qualified name

__init__(tag)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__str__() <==> str(x)[source]
text
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:

<parent>
    <root_tag>
        <tag>value1</tag>
        <tag>value2</tag>
    </root_tag>
</parent>

One could write:

sequenceElement[1] == "value2"
__abstractmethods__ = frozenset([])
__delitem__(index)[source]
__getitem__(index)[source]
__init__(parent, root_tag, element_tag, namespace='', indent=' ')[source]

x.__init__(…) initializes x; see help(type(x)) for signature

__len__()[source]
__setitem__(index, value)[source]
insert(index, value)[source]

S.insert(index, object) – insert object before index

class Writer(root_tag, attributes=None, tab_size=0)[source]

Pretty-print an XML tree.

__init__(root_tag, attributes=None, tab_size=0)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

marshal(node)[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(src)[source]

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