@std/data/xml.ms#
Import each required symbol with import Name from "@std/data/xml.ms".
XmlAttribute Type#
An XML attribute with its decoded value.
type XmlAttribute {
name String
value String
}XmlAttribute.name#
Attribute name as written, including any prefix.
name StringXmlAttribute.value#
Attribute value with references decoded.
value StringXmlNode Enum#
A node of a parsed XML tree.
enum XmlNode {
XmlElement(name String, attributes List[XmlAttribute], children List[XmlNode])
XmlText(text String)
XmlComment(text String)
}XmlNode.XmlComment#
A comment, without the delimiters.
XmlComment(text String)XmlNode.XmlElement#
An element with its attributes in source order and its child nodes.
XmlElement(name String, attributes List[XmlAttribute], children List[XmlNode])XmlNode.XmlText#
Character data with references decoded; CDATA sections become text.
XmlText(text String)XmlNode.XmlComment.text#
Comment contents exactly as written between the delimiters.
text StringXmlNode.XmlElement.attributes#
Attributes in source order.
attributes List[XmlAttribute]XmlNode.XmlElement.children#
Child elements, text and comments in document order.
children List[XmlNode]XmlNode.XmlElement.name#
Tag name as written, including any prefix.
name StringXmlNode.XmlText.text#
Text with entity and character references decoded.
text StringXmlNode.attribute#
Returns the value of the attribute name as a view, or null when it is absent or
the node is not an element.
fn attribute(name String) String?XmlNode.children#
Returns the child nodes of an element, or an empty list. The result is an owned copy.
fn children() List[XmlNode]XmlNode.find#
Returns the first direct child element named name as a view, or null.
fn find(name String) XmlNode?XmlNode.find_all#
Returns every direct child element named name, in order.
fn find_all(name String) List[XmlNode]XmlNode.tag#
The tag name of an element, or empty text for text and comments.
fn tag() StringXmlNode.text#
Returns all descendant text joined in document order, without comments.
fn text() Stringescape_attribute Function#
Escapes text for a double-quoted attribute value.
fn escape_attribute(text String) String { ... }escape_text Function#
Escapes &, <, > and carriage return for text content; a raw \r would read
back as \n.
fn escape_text(text String) String { ... }parse Function#
Parses a document with a single root element and returns that element.
When max_depth is set, it bounds element nesting; deeper input returns EOVERFLOW, and a
max_depth of zero or less returns EINVAL. null imposes no depth limit.
A document with several roots, text outside the root, or any syntax error returns EBADMSG.
Its message reads XML <line>:<column>: <reason>, and details holds line, column and
reason, counted in scalars after line ends are normalized.
An XML declaration is allowed only at the start, after an optional BOM. Its encoding
name is checked for valid syntax; the String input has already been decoded.
fn parse(text String, max_depth Int? = null) Result[XmlNode, Error] { ... }stringify Function#
Writes a node as XML. A non-empty indent (such as two spaces) puts each element on
its own line, except elements holding text, which stay on one line. An element with
no children is self-closing.
fn stringify(node XmlNode, indent String = "") String { ... }