Xml
Non-validating XML parser (pure March, no FFI, namespace-unaware).
Supports: elements, attributes (double/single-quoted), text nodes, CDATA sections, comments, processing instructions, XML declaration, DOCTYPE declarations (skipped), entity references (< > & " '), self-closing tags.
Public API: Xml.parse(src) : Result(XmlDoc, XmlError) Xml.parse_exn(src) : XmlDoc (panics on error) Xml.to_string(doc) : String Xml.to_string_pretty(doc) : String Xml.root(doc) : XmlNode Xml.tag(node) : Option(String) Xml.text(node) : Option(String) Xml.attr(node, name) : Option(String) Xml.children(node) : List(XmlNode) Xml.elements(node) : List(XmlNode) Xml.find(node, path) : Option(XmlNode) Xml.find_all(node, path) : List(XmlNode) Xml.elem(tag, attrs, kids) : XmlNode Xml.text_node(s) : XmlNode
Types
Functions
Get the value of an attribute by name, or None if absent.
Get all child nodes of an element (text, elements, comments, etc.).
Construct an element node.
Get only element-type children (filters out text, comments, etc.).
Navigate to the first node matching a slash-delimited tag path.
Xml.find(root, "item/name") -- finds <item><name>...</name></item>Find all element children at the last segment of a slash-delimited path.
Xml.find_all(root, "items/item") -- all <item> inside <items>Parse an XML string. Returns Ok(XmlDoc) on success or Err(XmlError) on failure. This is a non-validating parser: it does not check DTDs or enforce constraints beyond well-formedness.
Xml.parse("<root><item>hello</item></root>")
-- Ok(XmlDoc(None, Element("root", [], [Element("item", [], [Text("hello")])])))Get the tag name of an element node, or None for non-element nodes.
Get the concatenated direct text content of a node, or None if no text children.