rads.xml.base module

Generic XML tools, not relating to a specific backend.

class rads.xml.base.Element[source]

Bases: collections.abc.Iterable, typing.Generic, collections.abc.Sized, abc.ABC

A generic XML element.

Base class of XML elements.

dumps(*, indent: Union[int, str, None] = None, _current_indent: str = '') → str[source]

Get string representation of this element and all child elements.

Parameters

indent – Amount to indent each level. Can be given as an int or a string. Defaults to 4 spaces.

Returns

String representation of this and all child elements.

abstract next() → rads.xml.base.Element[source]

Get the next sibling element.

Returns

Next XML sibling element.

Raises

StopIteration – If there is no next sibling element.

abstract prev() → rads.xml.base.Element[source]

Get the previous sibling element.

Returns

Previous XML sibling element.

Raises

StopIteration – If there is no previous sibling element.

abstract up() → rads.xml.base.Element[source]

Get the parent of this element.

Returns

Parent XML element.

Raises

StopIteration – If there is no parent element.

abstract down() → rads.xml.base.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 opening_line

Get the opening line of the XML element.

Returns

Opening line number, or None.

property num_lines

Get the number of lines making up the XML element.

Returns

Number of lines in XML element, or None.

property closing_line

Get the closing line of the XML element.

Returns

Closing line number, or None.

abstract property tag

Tag name of the element.

abstract property text

Internal text of the element.

abstract property attributes

The attributes of the element, as a dictionary.