PyDocs

Structured Markup Processing Tools

xml.etree.ElementTree

Deprecated 3.3

Lightweight XML support for Python.

XML is an inherently hierarchical data format, and the most natural way to
represent it is with a tree.  This module has two classes for this purpose:

   1. ElementTree represents the whole XML document as a tree and

   2. Element represents a single node in this tree.

Interactions with the whole document (reading and writing to/from files) are
usually done on the ElementTree level.  Interactions with a single XML
element and its sub-elements are done on the Element level.

Element is a flexible container object designed to store hierarchical data
structures in memory. It can be described as a cross between a list and a
dictionary.  Each Element has a number of properties associated with it:

   'tag' - a string containing the element's name.

   'attributes' - a Python dictionary storing the element's attributes.

   'text' - a string containing the element's text content.

   'tail' - an optional string containing text after the element's end tag.

   And a number of child elements stored in a Python sequence.

To create an element instance, use the Element constructor,
or the SubElement factory function.

You can also use the ElementTree class to wrap an element structure
and convert it to and from XML.
Symbols in xml.etree.ElementTree

c

C14NWriterTarget
Canonicalization writer target for the XMLParser.
canonicalize
Convert XML to its C14N 2.0 serialised form.
Comment
Comment element factory.

d

dump
Write element tree or element structure to sys.stdout.

e

Element
Element class.
ElementTree
An XML element hierarchy.

f

fromstring
Parse XML document from string constant.
fromstringlist
Parse XML document from sequence of string fragments.

i

indent
Indent an XML document by inserting newlines and indentation space after elements.
iselement
Return True if *element* appears to be an Element.
iterparse
Incrementally parse XML document into ElementTree.

p

parse
Parse XML document into element tree.
ParseError
XML parse error, raised by the various parsing methods in this module when parsing fails.
ProcessingInstruction
Processing Instruction element factory.

q

QName
Qualified name wrapper.

r

register_namespace
Register a namespace prefix.

s

SubElement
Subelement factory.

t

tostring
Generate string representation of XML element.
tostringlist
Generates a string representation of an XML element, including all subelements.
TreeBuilder
Generic element structure builder.

x

XML
Parse XML document from string constant.
XMLID
Parse XML document from string constant for its IDs.
XMLParser
This class is the low-level building block of the module.
XMLPullParser
A pull parser suitable for non-blocking applications.