pywbem.tupletree

Package pywbem :: Module tupletree |
[frames] | no frames]

# Module tupletree

source code

tupletree - Convert XML DOM objects to and from tuple trees.

DOM is the standard in-memory representation of XML documents, but it is very cumbersome for some types of processing where XML encodes object structures rather than text documents. Direct mapping to Python classes may not be a good match either.

tupletrees may be created from an in-memory DOM using dom_to_tupletree(), or from a string using xml_to_tupletree().

Since the Python XML libraries deal mostly with Unicode strings they are also returned here. If plain Strings are passed in they will be converted by xmldom.

Each node of the tuple tree is a Python 4-tuple, corresponding to an XML Element (i.e. <tag>):

> (NAME, ATTRS, CONTENTS, None)

The NAME is the name of the element.

The ATTRS are a name-value hash of element attributes.

The CONTENTS is a list of child elements.

The fourth element is reserved.

Functions
dom_to_tupletree(node) Convert a DOM object to a pyRXP-style tuple tree. | source code
xml_to_tupletree(xml_string) Parse XML straight into tupletree. | source code

Function Details

### dom_to_tupletree(node) | source code
Convert a DOM object to a pyRXP-style tuple tree. Each element is a 4-tuple of (NAME, ATTRS, CONTENTS, None). Very nice for processing complex nested trees.