Capy-Bearer Documentation

xml_decode

lib call

Capy

function xml_decode(source : string) any

Description

xml_decode() returns a result whose value is an element tree. Each element has name, optional attrs, optional children, and optional text fields. Attribute values and text are strings. Missing fields return none.

The parser decodes predefined and numeric entities and reads CDATA. Comments and processing instructions do not appear in the result. It does not resolve external entities.

Mixed content loses its position relative to children. For <p>a<b>x</b>c</p>, the parent text is ac and the child text is x. Whitespace-only text chunks disappear. This is not a lossless XML representation.

Malformed XML, such as <a></b>, returns ok: false with an error message.

Parameters

source : XML source

Return Values

{ok: true, value: ...} on success, or {ok: false, error: "..."} on failure. The value field contains the element tree.

Example

Capy

var value := xml_decode("<root><name>Ada</name></root>").value
print(value["children"][0]["text"], "\n")

Output

Ada