Reference · reference
xml module
use xml parses and serializes XML over the Value type, for the configuration files that JSON and TOML do not cover, such as a .csproj or a web.config. config-weave registers it from wscript-std. Every function returns Result[…, string].
parse
parse
Parses an XML document into a Value. Elements nest as maps keyed by element name. Attributes are collected under @attrs, text under #text, and repeated child elements with the same name become a list.
| XML | Value |
|---|---|
| <cfg><name>weave</name></cfg> | {"cfg": {"name": "weave"}} |
| <a k="v">text</a> | {"a": {"@attrs": {"k": "v"}, "#text": "text"}} |
| <r><i>1</i><i>2</i></r> | {"r": {"i": ["1", "2"]}} |
Mixed content loses its order
Text interleaved with child elements is concatenated into one #text. <r>mixed<b>x</b>tail</r> parses to {"r": {"#text": "mixedtail", "b": "x"}}, so a round trip moves the text ahead of the child. This is fine for configuration files and wrong for documents. Produce documents with the template module instead.
to_string and to_string_pretty
to_string
to_string_pretty
Serializes a Value in the mapping above back to XML, compact or indented.
use fs
use xml
let doc = parse?
let config = doc.get