Skip to content

Xml Parser

Spice
import "std/text/xml-parser";

XmlParser struct

Recursive-descent XML parser. Use parseXml for one-shot parsing.

The parser handles a useful subset of XML 1.0: elements with attributes, self-closing tags, character data with the standard predefined entities (& < > " ') and numeric character references (&#NN; and &#xNN;), CDATA sections, comments and an optional XML declaration / processing instructions (which are skipped). DTDs, namespaces and external entities are not interpreted.

The XmlNode data model lives in "std/text/xml-node" and serialization in "std/text/xml-serializer".

Constructors

ctor

Spice
public p XmlParser.ctor(const String& input)

Construct an XML parser over the given input string

Parameters

Name Type Description
input const String& XML text to parse

Methods

parse

Spice
public f<Result<XmlNode*>> XmlParser.parse()

Parse the input string into an XML node tree

Returns: Result<XmlNode*> — Result holding the root XML node, or an error if the input is malformed

Functions

parseXml

Spice
public f<Result<XmlNode*>> parseXml(const String& input)

Parse an XML document and return the root element.

On success returns the root XmlNode (heap-allocated; the caller owns it). On failure returns an error describing the first problem encountered.

Parameters

Name Type Description
input const String&

Returns: Result<XmlNode*>