rads.xml.etree module¶
XML tools using xml.etree.ElementTree.
-
exception
rads.xml.etree.ParseError[source]¶ Bases:
SyntaxError
-
rads.xml.etree.fromstring(text, parser=None)¶ Parse XML document from string constant.
This function can be used to embed “XML Literals” in Python code.
text is a string containing XML data, parser is an optional parser instance, defaulting to the standard XMLParser.
Returns an Element instance.
-
rads.xml.etree.fromstringlist(sequence, parser=None)[source]¶ Parse XML document from sequence of string fragments.
sequence is a list of other sequence, parser is an optional parser instance, defaulting to the standard XMLParser.
Returns an Element instance.
-
rads.xml.etree.parse(source, parser=None)[source]¶ Parse XML document into element tree.
source is a filename or file object containing XML data, parser is an optional parser instance defaulting to XMLParser.
Return an ElementTree instance.
-
class
rads.xml.etree.Element(element: xml.etree.ElementTree.Element, *, index: Optional[int] = None, parent: Optional[Element] = None, file: Optional[str] = None)[source]¶ Bases:
rads.xml.base.ElementXML element that encapsulates an element from the ElementTree module.
Does not support line number examination.
Note
It is recommended to use
rads.xml.lxml.Elementif libxml is available on your system as the etree version does not support line numbers which can make debugging XML files for syntax errors more difficult.- Parameters
element – XML element from the standard
xml.etree.ElementTreepackage.index – Index of element at current level, among it’s siblings. Not required if this element does not have any siblings.
parent – The parent of this element.
file – Filename of the XML document.
-
next() → rads.xml.etree.Element[source]¶ Get the next sibling element.
- Returns
Next XML sibling element.
- Raises
StopIteration – If there is no next sibling element.
-
prev() → rads.xml.etree.Element[source]¶ Get the previous sibling element.
- Returns
Previous XML sibling element.
- Raises
StopIteration – If there is no previous sibling element.
-
up() → rads.xml.etree.Element[source]¶ Get the parent of this element.
- Returns
Parent XML element.
- Raises
StopIteration – If there is no parent element.
-
down() → rads.xml.etree.Element[source]¶ Get the first child of this element.
- Returns
First child XML element.
- Raises
StopIteration – If this element does not have any children.
-
property
file¶ Get the name of the XML file containing this element.
- Returns
Name of the file containing this element, or None.
-
property
tag¶ Tag name of the element.
-
property
text¶ Internal text of the element.
-
property
attributes¶ The attributes of the element, as a dictionary.
-
rads.xml.etree.error_with_file(error: xml.etree.ElementTree.ParseError, file: str) → xml.etree.ElementTree.ParseError[source]¶ Add filename to an XML parse error.
- Parameters
error – Original XML parse error.
file – Filename to add.
- Returns
A new parse error (of the same type as error) with the filename added.