The Element type is a flexible container object, designed to store hierarchical data structures in memory. The type can be described as a cross between a list and a dictionary.
Each element has a number of properties associated with it:
The ElementTree class can be used to wrap an element structure, and convert it from and to XML.
Internal element class.
For more information about this class, see The _ElementInterface Class.
Comment element factory. This factory function creates a special element that will be serialized as an XML comment.
The comment string can be either an 8-bit ASCII string or a Unicode string.
Writes an element tree or element structure to sys.stdout. This function should be used for debugging only.
The exact output format is implementation dependent. In this version, it's written as an ordinary XML file.
Element factory. This function returns an object implementing the standard Element interface. The exact class or type of that object is implementation dependent, but it will always be compatible with the _ElementInterface class in this module.
The element name, attribute names, and attribute values can be either 8-bit ASCII strings or Unicode strings.
ElementTree wrapper class.
For more information about this class, see The ElementTree Class.
Parses an XML document from a string constant. Same as XML.
Checks if an object appears to be a valid element object.
Parses an XML document into an element tree incrementally, and reports what's going on to the user.
For more information about this class, see The iterparse Class.
Parses an XML document into an element tree.
PI element factory. This factory function creates a special element that will be serialized as an XML processing instruction.
QName wrapper.
For more information about this class, see The QName Class.
Subelement factory. This function creates an element instance, and appends it to an existing element.
The element name, attribute names, and attribute values can be either 8-bit ASCII strings or Unicode strings.
Generates a string representation of an XML element, including all subelements.
Generic element structure builder.
For more information about this class, see The TreeBuilder Class.
Parses an XML document from a string constant. This function can be used to embed "XML literals" in Python code.
Parses an XML document from a string constant, and also returns a dictionary which maps from element id:s to elements.
Element structure builder for XML source data, based on the expat parser.
For more information about this class, see The XMLTreeBuilder Class.
Internal element class. This class defines the Element interface, and provides a reference implementation of this interface.
You should not create instances of this class directly. Use the appropriate factory functions instead, such as Element and SubElement.
Deletes the given subelement.
Deletes a number of subelements.
Returns the given subelement.
Returns a list containing subelements in the given range.
Returns the number of subelements.
Replaces the given subelement.
Replaces a number of subelements with elements from a sequence.
Adds a subelement to the end of this element.
(Attribute) Element attribute dictionary. Where possible, use get, set, keys, and items to access element attributes.
Resets an element. This function removes all subelements, clears all attributes, and sets the text and tail attributes to None.
Finds the first matching subelement, by tag name or path.
Finds all matching subelements, by tag name or path.
Finds text for the first matching subelement, by tag name or path.
Gets an element attribute.
Returns all subelements. The elements are returned in document order.
Creates a tree iterator. The iterator loops over this element and all subelements, in document order, and returns all elements with a matching tag.
If the tree structure is modified during iteration, the result is undefined.
Inserts a subelement at the given position in this element.
Gets element attributes, as a sequence. The attributes are returned in an arbitrary order.
Gets a list of attribute names. The names are returned in an arbitrary order (just like for an ordinary Python dictionary).
Creates a new element object of the same type as this element.
Removes a matching subelement. Unlike the find methods, this method compares elements based on identity, not on tag value or contents.
Sets an element attribute.
(Attribute) Element tag.
(Attribute) Text after this element's end tag, but before the next sibling element's start tag. This is either a string or the value None, if there was no text.
(Attribute) Text before first subelement. This is either a string or the value None, if there was no text.
ElementTree wrapper class. This class represents an entire element hierarchy, and adds some extra support for serialization to and from standard XML.
Replaces the root element for this tree. This discards the current contents of the tree, and replaces it with the given element. Use with care.
Finds the first toplevel element with given tag. Same as getroot().find(path).
Finds all toplevel elements with the given tag. Same as getroot().findall(path).
Finds the element text for the first toplevel element with given tag. Same as getroot().findtext(path).
Creates a tree iterator for the root element. The iterator loops over all elements in this tree, in document order.
Gets the root element for this tree.
Loads an external XML document into this element tree.
Writes the element tree to a file, as XML.
Parses an XML document into an element tree incrementally, and reports what's going on to the user.
QName wrapper. This can be used to wrap a QName attribute value, in order to get proper namespace handling on output.
Generic element structure builder. This builder converts a sequence of start, data, and end method calls to a well-formed element structure.
You can use this class to build an element structure using a custom XML parser, or a parser for some other XML-like format.
Flushes the parser buffers, and returns the toplevel documen element.
Adds text to the current element.
Closes the current element.
Opens a new element.
Element structure builder for XML source data, based on the expat parser.
Finishes feeding data to the parser.
Handles a doctype declaration.
Feeds data to the parser.