Package xmlschema_acue :: Module etree

Module etree

source code

This module contains ElementTree setup and helpers for xmlschema package.

Classes
  SafeXMLParser
An XMLParser that forbids entities processing.
Functions
 
is_etree_element(elem)
More safer test for matching ElementTree elements.
source code
 
etree_tostring(elem, namespaces=None, indent='', max_lines=None, spaces_for_tab=4, xml_declaration=False)
Serialize an Element tree to a string.
source code
 
etree_iterpath(elem, tag=None, path='.', namespaces=None, add_position=False)
Creates an iterator for the element and its subelements that yield elements and paths.
source code
 
etree_getpath(elem, root, namespaces=None, relative=True, add_position=False)
Returns the XPath path from *root* to descendant *elem* element.
source code
 
etree_last_child(elem)
Returns the last child of the element, ignoring children that are lxml comments.
source code
 
etree_child_index(elem, child)
Return the index or raise ValueError if it is not a *child* of *elem*.
source code
 
etree_elements_assert_equal(elem, other, strict=True, skip_comments=True)
Tests the equality of two XML Element trees.
source code
Variables
  lxml_etree = None
  PyElementTree = importlib.import_module('xml.etree.ElementTree')
  ElementTree = importlib.import_module('xml.etree.ElementTree')
  etree_element = ElementTree.Element
  etree_register_namespace = ElementTree.register_namespace
  ParseError = ElementTree.ParseError
  py_etree_element = PyElementTree.Element
  py_etree_register_namespace = ElementTree.register_namespace
  lxml_etree_element = None
  lxml_etree_comment = None
  lxml_etree_register_namespace = None
Function Details

etree_tostring(elem, namespaces=None, indent='', max_lines=None, spaces_for_tab=4, xml_declaration=False)

source code 

Serialize an Element tree to a string. Tab characters are replaced by whitespaces.

:param elem: the Element instance. :param namespaces: is an optional mapping from namespace prefix to URI. Provided namespaces are registered before serialization. :param indent: the base line indentation. :param max_lines: if truncate serialization after a number of lines (default: do not truncate). :param spaces_for_tab: number of spaces for replacing tab characters (default is 4). :param xml_declaration: if set to `True` inserts the XML declaration at the head. :return: a Unicode string.

Decorators:

etree_iterpath(elem, tag=None, path='.', namespaces=None, add_position=False)

source code 

Creates an iterator for the element and its subelements that yield elements and paths. If tag is not `None` or '*', only elements whose matches tag are returned from the iterator.

:param elem: the element to iterate. :param tag: tag filtering. :param path: the current path, '.' for default. :param add_position: add context position to child elements that appear multiple times. :param namespaces: is an optional mapping from namespace prefix to URI.

Decorators:

etree_getpath(elem, root, namespaces=None, relative=True, add_position=False)

source code 

Returns the XPath path from *root* to descendant *elem* element.

:param elem: the descendant element. :param root: the root element. :param namespaces: is an optional mapping from namespace prefix to URI. :param relative: returns a relative path. :param add_position: add context position to child elements that appear multiple times. :return: An XPath expression or `None` if *elem* is not a descendant of *root*.

Decorators:

etree_elements_assert_equal(elem, other, strict=True, skip_comments=True)

source code 

Tests the equality of two XML Element trees.

:param elem: the master Element tree, reference for namespace mapping. :param other: the other Element tree that has to be compared. :param strict: asserts strictly equality. `True` for default. :param skip_comments: Skip comments for e :raise: an AssertionError containing information about first difference encountered.

Decorators: