Manuscript Documentation
v2026.12.0

@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.

Manuscript
type XmlAttribute {
    name String
    value String
}

XmlAttribute.name#

Attribute name as written, including any prefix.

Manuscript
name String

XmlAttribute.value#

Attribute value with references decoded.

Manuscript
value String

XmlNode Enum#

A node of a parsed XML tree.

Manuscript
enum XmlNode {
    XmlElement(name String, attributes List[XmlAttribute], children List[XmlNode])
    XmlText(text String)
    XmlComment(text String)
}

XmlNode.XmlComment#

A comment, without the delimiters.

Manuscript
XmlComment(text String)

XmlNode.XmlElement#

An element with its attributes in source order and its child nodes.

Manuscript
XmlElement(name String, attributes List[XmlAttribute], children List[XmlNode])

XmlNode.XmlText#

Character data with references decoded; CDATA sections become text.

Manuscript
XmlText(text String)

XmlNode.XmlComment.text#

Comment contents exactly as written between the delimiters.

Manuscript
text String

XmlNode.XmlElement.attributes#

Attributes in source order.

Manuscript
attributes List[XmlAttribute]

XmlNode.XmlElement.children#

Child elements, text and comments in document order.

Manuscript
children List[XmlNode]

XmlNode.XmlElement.name#

Tag name as written, including any prefix.

Manuscript
name String

XmlNode.XmlText.text#

Text with entity and character references decoded.

Manuscript
text String

XmlNode.attribute#

Returns the value of the attribute name as a view, or null when it is absent or the node is not an element.

Manuscript
fn attribute(name String) String?

XmlNode.children#

Returns the child nodes of an element, or an empty list. The result is an owned copy.

Manuscript
fn children() List[XmlNode]

XmlNode.find#

Returns the first direct child element named name as a view, or null.

Manuscript
fn find(name String) XmlNode?

XmlNode.find_all#

Returns every direct child element named name, in order.

Manuscript
fn find_all(name String) List[XmlNode]

XmlNode.tag#

The tag name of an element, or empty text for text and comments.

Manuscript
fn tag() String

XmlNode.text#

Returns all descendant text joined in document order, without comments.

Manuscript
fn text() String

escape_attribute Function#

Escapes text for a double-quoted attribute value.

Manuscript
fn escape_attribute(text String) String { ... }

escape_text Function#

Escapes &, <, > and carriage return for text content; a raw \r would read back as \n.

Manuscript
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.

Manuscript
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.

Manuscript
fn stringify(node XmlNode, indent String = "") String { ... }