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

Module etree


Version: 1.3.6-48216

Functions [hide private]
 
Comment(...)
Comment element factory.
 
Element(...)
Element factory.
 
ElementTree(...)
ElementTree wrapper class.
 
Extension(...)
 
FunctionNamespace(...)
Retrieve the function namespace object associated with the given URI.
 
HTML(...)
Parses an HTML document from a string constant.
 
Namespace(...)
Retrieve the namespace object associated with the given URI.
 
PI(...)
Comment element factory.
 
ProcessingInstruction(...)
Comment 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.
 
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(...)
 
set_default_parser(...)
Set a default parser for the current thread.
 
tostring(...)
Serialize an element to an encoded string representation of its XML tree.
 
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, 30)
  LIBXML_VERSION = (2, 6, 30)
  LIBXSLT_COMPILED_VERSION = (1, 1, 21)
  LIBXSLT_VERSION = (1, 1, 21)
  LXML_VERSION = (1, 3, 6, 48216)
  _import_c_api = <PyCObject object at 0x85ff488>
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.

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, ...).

Namespace(...)

 

Retrieve the namespace object associated with the given URI. Creates a new one if it does not yet exist.

PI(...)

 

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

ProcessingInstruction(...)

 

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

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.

XPath evaluators must not be shared between threads.

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, ...).

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.

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.

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.