XML Module
You can use the XML module to read or write XML data. XML documents are represented as a DOM (Document Object Model) struture.
Examples
Reading an XML document
Creating an XML document
Types
QName
QName
Represents a qualified name with an optional namespace.
Attribute
Attribute
Represents an XML attribute.
Element
Element
Represents an XML element.
Document
Document
Represents an XML document with a root element.
Node
Node
A union type representing different kinds of XML nodes.
Functions
Functions for reading XML
parse(value: text) -> Document
parse(value: text) -> Document
Parses an XML string into a Document
.
value
: The XML text to parse.Returns: A
Document
representing the parsed XML.
getDescendants(self el: Element) -> Element*
getDescendants(self el: Element) -> Element*
Returns all descendant elements of the given element, including itself.
el
: The element from which to start traversal.Returns: A sequence of all descendant elements.
getNamedChildren(self el: Element?, localName: text) -> Element*
getNamedChildren(self el: Element?, localName: text) -> Element*
Finds all direct child elements with the given local name.
el
: The parent element.localName
: The name of the child elements to retrieve.Returns: A sequence of matching elements.
getNamedChild(self el: Element?, localName: text) -> Element?
getNamedChild(self el: Element?, localName: text) -> Element?
Finds the first direct child element with the given local name.
el
: The parent element.localName
: The name of the child element to retrieve.Returns: The first matching child element or
null
if none is found.
getNamedAttribute(self el: Element?, localName: text) -> Attribute?
getNamedAttribute(self el: Element?, localName: text) -> Attribute?
Finds an attribute by its local name.
el
: The element to search in.localName
: The name of the attribute.Returns: The matching attribute or
null
if not found.
getChildren(self el: Element?) -> Element*
getChildren(self el: Element?) -> Element*
Returns the direct children of an element.
el
: The parent element.Returns: A sequence of child elements.
Functions for creating XML
print(doc: Document) -> text
print(doc: Document) -> text
Serializes a Document
into an XML string.
doc
: The document to serialize.Returns: The XML text representation of the document.
document(root: Element) -> Document
document(root: Element) -> Document
Creates a new XML document with the given root element.
root
: The root element.Returns: A
Document
.
element(name: text | QName, ...contents: Node*) -> Element
element(name: text | QName, ...contents: Node*) -> Element
Creates an XML element with the given name and contents.
name
: The name of the element.contents
: A sequence of child elements, attributes, and text nodes.Returns: An
Element
.
attribute(name: text | QName, value: text) -> Attribute
attribute(name: text | QName, value: text) -> Attribute
Creates an XML attribute with the given name and value.
name
: The name of the attribute.value
: The value of the attribute.Returns: An
Attribute
.
qualifiedName(namespace: text?, localName: text) -> QName
qualifiedName(namespace: text?, localName: text) -> QName
Creates a qualified name with an optional namespace.
namespace
: (Optional) The namespace.localName
: The local name.Returns: A
QName
.
Last updated
Was this helpful?