Module: anynet.xml
Provides classes and functions to work with XML documents.
class XMLTree
Represents an XML tree or a subtree.
def parse(text: str) -> XMLTree
Parses an XML document and returns an XMLTree. Entities are decoded automatically. Raises ValueError is text does not contain a valid XML document.
XMLTree
children: list[XMLTree] = []
The children of the root node.
attrs: dict[str, str] = {}
The attributes of the root node.
text: str = ""
The text in the root node that does not belong to a child tag.
name: str = ""
The tag name of the root node
def __init__(name: str)
Creates a new XML tree with the given tag name.
def __contains__(name: str) -> bool
Checks if a child with the given tag name exists.
def __getitem__(name: str) -> XMLTree
Returns the first child with the given tag name. Raises KeyError if no such child exists.
def __iter__() -> Iterator
Returns an iterator over the children.
def __len__() -> int
Returns the number of children.
def find(name: str) -> list[XMLTree]
Returns all children with the given tag name.
def add(name: str, text: str = "", attrs: dict[str, str] = {}) -> XMLTree
Creates a new child with the given tag name, text and attributes, and adds it to the XML tree. Returns the new child.
def encode() -> str
Encodes the XML tree recursively. Special characters are converted to entities automatically. No insignificant whitespace or XML declaration is added to the document.