xml

meth xml::parse(Stream: stream): xml

Returns the contents of Stream parsed into an XML node.

fun xml::escape(String: string): string

Escapes characters in String.

import: xml("fmt/xml")
xml::escape("\'1 + 2 > 3 & 2 < 4\'")
:> "\'1 + 2 &gt; 3 &amp; 2 &lt; 4\'"
meth xml::parse(String: string): xml

Returns String parsed into an XML node.

type xml

An XML node.

meth xml(Stream: stream): xml

Returns the contents of Stream parsed into an XML node.

meth xml(String: string): xml

Returns String parsed into an XML node.

meth xml(Tag: symbol, ...): xml

Returns a new xml element with tag Tag, adding attributes and children as xml::element(...).

meth (Xml: xml) / (Fn: function): sequence

Returns a sequence of the children of Xml for which Fn(Child) is non-nil.

meth (Xml: xml) / (Attribute₁ is Value₁, ...): sequence

Returns a sequence of the children of Xml with Attribute₁ = Value₁, etc.

meth (Xml: xml) / (Tag: string): sequence

Returns a sequence of the children of Xml with tag Tag.

meth (Xml: xml) / (Tag: string, Attribute₁ is Value₁, ...): sequence

Returns a sequence of the children of Xml with tag Tag and Attribute₁ = Value₁, etc.

meth (Xml: xml) // (Fn: function): sequence

Returns a sequence of the recursive children of Xml for which Fn(Child) is non-nil.

meth (Xml: xml) // (Attribute₁ is Value₁, ...): sequence

Returns a sequence of the recursive children of Xml with Attribute₁ = Value₁, etc.

meth (Xml: xml) // (Tag: string): sequence

Returns a sequence of the recursive children of Xml with tag Tag.

meth (Xml: xml) // (Tag: string, Attribute₁ is Value₁, ...): sequence

Returns a sequence of the recursive children of Xml with tag Tag and Attribute₁ = Value₁, etc.

meth (Xml: xml) << (Fn: function): sequence

Returns a sequence of the previous siblings of Xml for which Fn(Child) is non-nil.

meth (Xml: xml) << (Attribute₁ is Value₁, ...): sequence

Returns a sequence of the previous siblings of Xml with Attribute₁ = Value₁, etc.

meth (Xml: xml) << (Tag: string): sequence

Returns a sequence of the previous siblings of Xml with tag Tag.

meth (Xml: xml) << (Tag: string, Attribute₁ is Value₁, ...): sequence

Returns a sequence of the previous siblings of Xml with tag Tag and Attribute₁ = Value₁, etc.

meth (Xml: xml) >> (Fn: function): sequence

Returns a sequence of the next siblings of Xml for which Fn(Child) is non-nil.

meth (Xml: xml) >> (Attribute₁ is Value₁, ...): sequence

Returns a sequence of the next siblings of Xml with Attribute₁ = Value₁, etc.

meth (Xml: xml) >> (Tag: string): sequence

Returns a sequence of the next siblings of Xml with tag Tag.

meth (Xml: xml) >> (Tag: string, Attribute₁ is Value₁, ...): sequence

Returns a sequence of the next siblings of Xml with tag Tag and Attribute₁ = Value₁, etc.

meth (Node: xml):add_next(Other: any, ...): xml

Inserts Other directly after Node.

meth (Node: xml):add_prev(Other: any, ...): xml

Inserts Other directly before Node.

meth (Node: xml):index: integer | nil

Returns the index of Node in its parent or nil.

meth (Xml: xml):next: xml | nil

Returns the next sibling of Xml or nil.

meth (Xml: xml):next(N: integer): xml | nil

Returns the N-th next sibling of Xml or nil.

meth (Xml: xml):parent: xml | nil

Returnst the parent of Xml or nil.

meth (Xml: xml):parent(N: integer): xml | nil

Returns the N-th parent of Xml or nil.

meth (Xml: xml):parent(Tag: string): xml | nil

Returns the ancestor of Xml with tag Tag if one exists, otherwise nil.

meth (Xml: xml):prev: xml | nil

Returnst the previous sibling of Xml or nil.

meth (Xml: xml):prev(N: integer): xml | nil

Returns the N-th previous sibling of Xml or nil.

meth (Node: xml):remove: xml

Removes Node from its parent.

type xml::element < xml, sequence

An XML element node.

meth xml::element(Tag: string, Arg₁, : any, ...): xml::element

Returns a new XML node with tag Tag and optional children and attributes depending on the types of each Argᵢ:

  • string: added as child text node. Consecutive strings are added a single node.

  • xml: added as a child node.

  • list: each value must be a string or xml and is added as above.

  • map: keys and values must be strings, set as attributes.

  • name is value: values must be strings, set as attributes.

import: xml("fmt/xml")
xml::element("test", "Text", type is "example")
:> error("XMLError", "Attribute values must be strings")
meth (Parent: xml::element) :: (Attribute: string): string | nil

Returns the value of the Attribute attribute of Parent.

meth /(Xml: xml::element): sequence

Returns a sequence of the children of Xml.

meth //(Xml: xml::element): sequence

Returns a sequence of the recursive children of Xml, including Xml.

meth <<(Xml: xml::element): sequence

Returns a sequence of the previous siblings of Xml.

meth >>(Xml: xml::element): sequence

Returns a sequence of the next siblings of Xml.

meth (Parent: xml::element)[Index: integer]: xml | nil

Returns the Index-th child of Parent or nil.

meth (Parent: xml::element)[Attribute: string]: string | nil

Returns the value of the Attribute attribute of Parent.

meth (Xml: xml::element):attributes: map

Returns the attributes of Xml.

meth (Parent: xml::element):empty: xml

Removes the contents of Parent.

meth (Parent: xml::element):grow(Children: sequence, ...): xml

Adds each node generated by Children to Parent and returns Parent.

meth (Parent: xml::element):put(Child: any, ...): xml

Adds Child to Parent.

meth (Xml: xml::element):set(Attribute: string, Value: string): xml

Sets the value of attribute Attribute in Xml to Value and returns Xml.

meth (Xml: xml::element):tag: string

Returns the tag of Xml.

meth (Xml: xml::element):text: string

Returns the (recursive) text content of Xml.

meth (Xml: xml::element):text(Sep: string): string

Returns the (recursive) text content of Xml, adding Sep between the contents of adjacent nodes.

meth (Buffer: string::buffer):append(Xml: xml::element)

Appends a string representation of Xml to Buffer.

type xml::filter < function

An XML filter.

meth xml::filter(Attr₁ is Value₁, ...): xml::filter

Returns an XML filter that checks if a node has attributes Attrᵢ = Valueᵢ.

meth xml::filter(Tag: string, Attr₁ is Value₁, ...): xml::filter

Returns an XML filter that checks if a node has tag Tag and attributes Attrᵢ = Valueᵢ.

type xml::parser < stream

A callback based streaming XML parser.

fun xml::parser(Callback: any): xml::parser

Returns a new parser that calls Callback(Xml) each time a complete XML document is parsed.

meth (Sequence: xml::sequence) / (Args: any, ...): sequence

Generates the sequence Nodeᵢ / Args where Nodeᵢ are the nodes generated by Sequence.

meth (Sequence: xml::sequence) // (Args: any, ...): sequence

Generates the sequence Nodeᵢ // Args where Nodeᵢ are the nodes generated by Sequence.

meth (Sequence: xml::sequence) << (Args: any, ...): sequence

Generates the sequence Nodeᵢ << Args where Nodeᵢ are the nodes generated by Sequence.

meth (Sequence: xml::sequence) >> (Args: any, ...): sequence

Generates the sequence Nodeᵢ >> Args where Nodeᵢ are the nodes generated by Sequence.

meth (Sequence: xml::sequence):contains(Regex: regex): sequence

Equivalent to Sequence ->? fun(X) X:text:find(Regex).

meth (Sequence: xml::sequence):contains(String: string): sequence

Equivalent to Sequence ->? fun(X) X:text:find(String).

meth (Sequence: xml::sequence):has(Fn: function): sequence

Equivalent to Sequence ->? fun(X) some(Fn(X)).

meth (Sequence: xml::sequence):next(Args: any, ...): sequence

Generates the sequence Nodeᵢ + Args where Nodeᵢ are the nodes generated by Sequence.

meth (Sequence: xml::sequence):parent(Args: any, ...): sequence

Generates the sequence Nodeᵢ ^ Args where Nodeᵢ are the nodes generated by Sequence.

meth (Sequence: xml::sequence):prev(Args: any, ...): sequence

Generates the sequence Nodeᵢ - Args where Nodeᵢ are the nodes generated by Sequence.

type xml::text < xml, string

A XML text node.

meth (Xml: xml::text):text: string

Returns the text content of Xml.