Package translate :: Package misc :: Module xml_helpers

[hide private]
[frames] | no frames]

# Module xml_helpers

source code

Helper functions for working with XML.

Functions | [hide private]

getText(node, xml_space=`'``preserve``'`) Extracts the plain text content out of the given node. | source code

getXMLlang(node) Gets the xml:lang attribute on node | source code

setXMLlang(node, lang) Sets the xml:lang attribute on node | source code

getXMLspace(node, default=None) Gets the xml:space attribute on node | source code

setXMLspace(node, value) Sets the xml:space attribute on node | source code

namespaced(namespace, name) Returns name in Clark notation within the given namespace. | source code

normalize_space(text) Normalize the given text for implimentation of xml:space="default". | source code

normalize_xml_space(node, xml_space, remove_start=False) normalize spaces following the nodes xml:space, or alternatively the given xml_space parameter. | source code

Variables | [hide private]

| xml_preserve_ancestors = `etree.XPath("ancestor-or-self::*[attr`...`` All ancestors with xml:space='preserve'
| xml_space_ancestors = `etree.XPath("ancestor-or-self::*/attribu`...`` All xml:space attributes in the ancestors
| string_xpath = `etree.XPath("string()")` Return a non-normalized string in the node subtree
| string_xpath_normalized = `etree.XPath("normalize-space()")` Return a (space) normalized string in the node subtree
| XML_NS = ``'``http://www.w3.org/XML/1998/namespace``'``
| MULTIWHITESPACE_PATTERN = ``'``[\\n\\r\\t ]+``'``
| MULTIWHITESPACE_RE = `re.compile(r'`(?m)``[`\n\r\t `]``+`')`

Imports: re, etree

Function Details | [hide private]

### getText(node, xml_space=`'``preserve``'`)

source code

Extracts the plain text content out of the given node.

This method checks the xml:space attribute of the given node, and takes an optional default to use in case nothing is specified in this node.

### namespaced(namespace, name)

source code

Returns name in Clark notation within the given namespace.

For example namespaced("source") in an XLIFF document might return:

       {urn:oasis:names:tc:xliff:document:1.1}source

This is needed throughout lxml.

Variables Details | [hide private]

### xml_preserve_ancestors

All ancestors with xml:space='preserve'

Value:

      etree.XPath("ancestor-or-self::*[attribute::xml:space='preserve']")

### xml_space_ancestors

All xml:space attributes in the ancestors

Value:

      etree.XPath("ancestor-or-self::*/attribute::xml:space")