Package lxml :: Module etree
[hide private]
[frames] | no frames]

Module etree



Classes [hide private]
  AncestorsIterator
Iterates over the ancestors of an element (from parent to parent).
  AttributeBasedElementClassLookup
Checks an attribute of an Element and looks up the value in a class dictionary.
  CommentBase
All custom Comment classes must inherit from this one.
  CustomElementClassLookup
Element class lookup based on a subclass method.
  DTD
A DTD validator.
  DocInfo
Document information provided by parser and DTD.
  ETCompatXMLParser
An XML parser with an ElementTree compatible default setup.
  ETXPath
Special XPath class that supports the ElementTree {uri} notation for namespaces.
  ElementBase
All custom Element classes must inherit from this one.
  ElementChildIterator
Iterates over the children of an element.
  ElementClassLookup
Superclass of Element class lookups.
  ElementDefaultClassLookup
Element class lookup scheme that always returns the default Element class.
  ElementDepthFirstIterator
Iterates over an element and its sub-elements in document order (depth first pre-order).
  ElementNamespaceClassLookup
Element class lookup scheme that searches the Element class in the Namespace registry.
  ElementTextIterator
Iterates over the text content of a subtree.
  EntityBase
All custom Entity classes must inherit from this one.
  FallbackElementClassLookup
Superclass of Element class lookups with additional fallback.
  HTMLParser
The HTML parser.
  PIBase
All custom Processing Instruction classes must inherit from this one.
  ParserBasedElementClassLookup
Element class lookup based on the XML parser.
  PyErrorLog
A global error log that connects to the Python stdlib logging package.
  QName
QName wrapper.
  RelaxNG
Turn a document into a Relax NG validator.
  Resolver
This is the base class of all resolvers.
  Schematron
A Schematron validator.
  SiblingsIterator
Iterates over the siblings of an element.
  XMLParser
The XML parser.
  XMLSchema
Turn a document into an XML Schema validator.
  XPath
A compiled XPath expression that can be called on Elements and ElementTrees.
  XPathDocumentEvaluator
Create an XPath evaluator for an ElementTree.
  XPathElementEvaluator
Create an XPath evaluator for an element.
  XSLT
Turn a document into an XSLT object.
  XSLTAccessControl
Access control for XSLT: reading/writing files, directories and network I/O.
  _Attrib
  _AttribIterator
Attribute iterator - for internal use only!
  _BaseContext
  _BaseErrorLog
  _BaseParser
  _ClassNamespaceRegistry
Dictionary-like registry for namespace implementation classes
  _Comment
  _Document
Internal base class to reference a libxml document.
  _DomainErrorLog
  _Element
Element class.
  _ElementIterator
  _ElementTagMatcher
  _ElementTree
  _Entity
  _ErrorLog
  _ExceptionContext
  _ExsltRegExp
  _FeedParser
  _FileReaderContext
  _FilelikeWriter
  _FunctionNamespaceRegistry
  _IDDict
A dictionary-like proxy class that mapps ID attributes to elements.
  _InputDocument
  _IterparseContext
  _ListErrorLog
Immutable base version of a list based error log.
  _LogEntry
  _NamespaceRegistry
Dictionary-like namespace registry
  _ParserContext
  _ParserDictionaryContext
  _ProcessingInstruction
  _ResolverContext
  _ResolverRegistry
  _RotatingErrorLog
  _TargetParserContext
This class maps SAX2 events to the ET parser target interface.
  _TempStore
  _Validator
Base class for XML validators.
  _XPathContext
  _XPathEvaluatorBase
  _XPathFunctionNamespaceRegistry
  _XSLTContext
  _XSLTProcessingInstruction
  _XSLTResolverContext
  _XSLTResultTree
  __ContentOnlyElement
  iterparse
Incremental parser.
  iterwalk
A tree walker that generates events from an existing tree as if it was parsing XML data with ``iterparse()``.
Functions [hide private]
 
Comment(...)
Comment element factory.
 
Element(...)
Element factory.
 
ElementTree(...)
ElementTree wrapper class.
 
Entity(...)
Entity factory.
 
Extension(...)
 
FunctionNamespace(...)
Retrieve the function namespace object associated with the given URI.
 
HTML(...)
Parses an HTML document from a string constant.
 
PI(...)
ProcessingInstruction element factory.
 
ProcessingInstruction(...)
ProcessingInstruction element factory.
 
SubElement(...)
Subelement factory.
 
XML(...)
Parses an XML document from a string constant.
 
XMLDTDID(...)
Parse the text and return a tuple (root node, ID dictionary).
 
XMLID(...)
Parse the text and return a tuple (root node, ID dictionary).
 
XPathEvaluator(...)
Creates an XPath evaluator for an ElementTree or an Element.
 
clearErrorLog(...)
Clear the global error log.
 
dump(...)
Writes an element tree or element structure to sys.stdout.
 
fromstring(...)
Parses an XML document from a string.
 
fromstringlist(...)
Parses an XML document from a sequence of strings.
 
getDefaultParser(...)
Deprecated, please use get_default_parser instead.
 
get_default_parser(...)
 
iselement(...)
Checks if an object appears to be a valid element object.
 
parse(...)
Return an ElementTree object loaded with source elements.
 
parseid(...)
Parses the source into a tuple containing an ElementTree object and an ID dictionary.
 
setDefaultParser(...)
Deprecated, please use set_default_parser instead.
 
setElementClassLookup(...)
Deprecated, use ``set_element_class_lookup(lookup)`` instead
 
set_default_parser(...)
Set a default parser for the current thread.
 
set_element_class_lookup(...)
Set the global default element class lookup method.
 
tostring(...)
Serialize an element to an encoded string representation of its XML tree.
 
tostringlist(...)
Serialize an element to an encoded string representation of its XML tree, stored in a list of partial strings.
 
tounicode(...)
Serialize an element to the Python unicode representation of its XML tree.
 
useGlobalPythonLog(...)
Replace the global error log by an etree.PyErrorLog that uses the standard Python logging package.
Variables [hide private]
  DEBUG = 1
  LIBXML_COMPILED_VERSION = (2, 6, 27)
  LIBXML_VERSION = (2, 6, 27)
  LIBXSLT_COMPILED_VERSION = (1, 1, 20)
  LIBXSLT_VERSION = (1, 1, 20)
  LXML_VERSION = (2, 0, -196, 47253)
  __version__ = '2.0.alpha4-47253'
  _import_c_api = <PyCObject object at 0x855b920>
Function Details [hide private]

Comment(...)

 
Comment element factory. This factory function creates a special element that will be serialized as an XML comment.

Element(...)

 
Element factory. This function returns an object implementing the Element interface.

Entity(...)

 
Entity factory. This factory function creates a special element that will be serialized as an XML entity. Note, however, that the entity will not be automatically declared in the document. A document that uses entities requires a DTD.

FunctionNamespace(...)

 
Retrieve the function namespace object associated with the given URI. Creates a new one if it does not yet exist. A function namespace can only be used to register extension functions.

HTML(...)

 

Parses an HTML document from a string constant. This function can be used to embed "HTML literals" in Python code.

To override the parser with a different ``HTMLParser`` you can pass it to the ``parser`` keyword argument.

The ``base_url`` keyword argument allows to set the original base URL of the document to support relative Paths when looking up external entities (DTD, XInclude, ...).

PI(...)

 
ProcessingInstruction element factory. This factory function creates a special element that will be serialized as an XML processing instruction.

ProcessingInstruction(...)

 
ProcessingInstruction element factory. This factory function creates a special element that will be serialized as an XML processing instruction.

SubElement(...)

 
Subelement factory. This function creates an element instance, and appends it to an existing element.

XML(...)

 
Parses an XML document from a string constant. This function can be used to embed "XML literals" in Python code, like in
>>> root = etree.XML("<root><test/></root>")

To override the parser with a different ``XMLParser`` you can pass it to the ``parser`` keyword argument.

The ``base_url`` keyword argument allows to set the original base URL of the document to support relative Paths when looking up external entities (DTD, XInclude, ...).

XMLDTDID(...)

 

Parse the text and return a tuple (root node, ID dictionary). The root node is the same as returned by the XML() function. The dictionary contains string-element pairs. The dictionary keys are the values of ID attributes as defined by the DTD. The elements referenced by the ID are stored as dictionary values.

Note that you must not modify the XML tree if you use the ID dictionary. The results are undefined.

XMLID(...)

 
Parse the text and return a tuple (root node, ID dictionary). The root node is the same as returned by the XML() function. The dictionary contains string-element pairs. The dictionary keys are the values of 'id' attributes. The elements referenced by the ID are stored as dictionary values.

XPathEvaluator(...)

 

Creates an XPath evaluator for an ElementTree or an Element.

The resulting object can be called with an XPath expression as argument and XPath variables provided as keyword arguments.

Additional namespace declarations can be passed with the 'namespace' keyword argument. EXSLT regular expression support can be disabled with the 'regexp' boolean keyword (defaults to True).

clearErrorLog(...)

 
Clear the global error log. Note that this log is already bound to a fixed size.

dump(...)

 
Writes an element tree or element structure to sys.stdout. This function should be used for debugging only.

fromstring(...)

 

Parses an XML document from a string.

To override the default parser with a different parser you can pass it to the ``parser`` keyword argument.

The ``base_url`` keyword argument allows to set the original base URL of the document to support relative Paths when looking up external entities (DTD, XInclude, ...).

fromstringlist(...)

 

Parses an XML document from a sequence of strings.

To override the default parser with a different parser you can pass it to the ``parser`` keyword argument.

parse(...)

 
Return an ElementTree object loaded with source elements. If no parser is provided as second argument, the default parser is used.

parseid(...)

 

Parses the source into a tuple containing an ElementTree object and an ID dictionary. If no parser is provided as second argument, the default parser is used.

Note that you must not modify the XML tree if you use the ID dictionary. The results are undefined.

set_default_parser(...)

 

Set a default parser for the current thread. This parser is used globally whenever no parser is supplied to the various parse functions of the lxml API. If this function is called without a parser (or if it is None), the default parser is reset to the original configuration.

Note that the pre-installed default parser is not thread-safe. Avoid the default parser in multi-threaded environments. You can create a separate parser for each thread explicitly or use a parser pool.

tostring(...)

 

Serialize an element to an encoded string representation of its XML tree.

Defaults to ASCII encoding without XML declaration. This behaviour can be configured with the keyword arguments 'encoding' (string) and 'xml_declaration' (bool). Note that changing the encoding to a non UTF-8 compatible encoding will enable a declaration by default.

The keyword argument 'pretty_print' (bool) enables formatted XML.

The keyword argument 'method' selects the output method: 'xml' or 'html'.

tostringlist(...)

 

Serialize an element to an encoded string representation of its XML tree, stored in a list of partial strings.

This is purely for ElementTree 1.3 compatibility. The result is a single string wrapped in a list.

tounicode(...)

 

Serialize an element to the Python unicode representation of its XML tree.

Note that the result does not carry an XML encoding declaration and is therefore not necessarily suited for serialization to byte streams without further treatment.

The keyword argument 'pretty_print' (bool) enables formatted XML.

The keyword argument 'method' selects the output method: 'xml' or 'html'.

useGlobalPythonLog(...)

 

Replace the global error log by an etree.PyErrorLog that uses the standard Python logging package.

Note that this disables access to the global error log from exceptions. Parsers, XSLT etc. will continue to provide their normal local error log.