Module: xml
asXml
Back to Index{ text -> value } |> ({ indent: boolean encoding: 'ascii' | 'utf8'}) [byte]
Turns a valid structure into an XML byte iterator.
Input Model
The input to asXml is a nested structure of Maps (or Records) representing nodes in the output XML.
The root node must be an element node but the type
field can be left out (as it’s implied).
Element Nodes
The bread and butter of XML are elements. Here’s the type outline of an XML node:
type Node { type: 'element' name: text attributes: { text -> text } | nothing node: [Node] | nothing}
Text Nodes
Aside from elements, an XML element can contain text nodes, for example <tag>This is a <b>text</b> node</tag>
.
Here’s the type definition:
type Node { type: 'text' value: text}
Error Handling
asXml
will optimistically format the XML. This means that invalid input will simply be ignored.
Availability
Discount | Rule | Reactor |
---|---|---|
Examples
import 'xml'
from { type = 'element' name = 'doc' attributes = { id = 'test' } nodes = [{ type = 'element' name = 'sub-tag' nodes = [{ type = 'text' value = 'textValue' },{ type = 'element' name = 'el' }] }]} asXml { indent = true}
Output:
<?xml version="1.0" encoding="UTF-8"?><doc id="test"> <sub-tag> textValue <el/> </sub-tag></doc>