xml
Build, serialize, and parse XML/SVG.
Naming convention: import the module under its bare name (
import "xml"), reach members with a backslash, and call methods incamelCase:xml\someMethod.
Methods
render
Serialize an XML node to a string. A node is a string (text) or an element map {"tag": name, "attrs": [name, value, ...], "children": [node, ...]}. Empty-children elements self-close; no whitespace is emitted between tags.
Signature: xml\render(node) → string · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
node |
any |
Returns: string
element
Build an element node from a tag, a flat [name, value, ...] attribute list, and a list of child nodes (elements or strings). Sugar for the {"tag", "attrs", "children"} map that render consumes.
Signature: xml\element(tag, attrs, children) → any · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
tag |
string |
||
attrs |
[]string |
||
children |
any |
Returns: any
parse
Parse an XML string into a node tree: each element becomes {"tag": name, "attrs": [name, value, ...], "children": [node, ...]}, character data becomes a string. The inverse shape of render.
Signature: xml\parse(s) → any · source
| Parameter | Type | Optional | Description |
|---|---|---|---|
s |
string |
Returns: any