xml¶
meth xml::parse(String: address): xml
Returns
String
parsed into an XML node.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 > 3 & 2 < 4\'"
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 asxml::element(...)
.meth (Xml: xml) / (Fn: function): sequence
Returns a sequence of the children of
Xml
for whichFn(Child)
is non-nil.meth (Xml: xml) / (Attribute₁ is Value₁, ...): sequence
Returns a sequence of the children of
Xml
withAttribute₁ = Value₁
, etc.meth (Xml: xml) / (Tag: string): sequence
Returns a sequence of the children of
Xml
with tagTag
.meth (Xml: xml) / (Tag: string, Attribute₁ is Value₁, ...): sequence
Returns a sequence of the children of
Xml
with tagTag
andAttribute₁ = Value₁
, etc.meth (Xml: xml) // (Fn: function): sequence
Returns a sequence of the recursive children of
Xml
for whichFn(Child)
is non-nil.meth (Xml: xml) // (Attribute₁ is Value₁, ...): sequence
Returns a sequence of the recursive children of
Xml
withAttribute₁ = Value₁
, etc.meth (Xml: xml) // (Tag: string): sequence
Returns a sequence of the recursive children of
Xml
with tagTag
.meth (Xml: xml) // (Tag: string, Attribute₁ is Value₁, ...): sequence
Returns a sequence of the recursive children of
Xml
with tagTag
andAttribute₁ = Value₁
, etc.meth (Xml: xml) << (Fn: function): sequence
Returns a sequence of the previous siblings of
Xml
for whichFn(Child)
is non-nil.meth (Xml: xml) << (Attribute₁ is Value₁, ...): sequence
Returns a sequence of the previous siblings of
Xml
withAttribute₁ = Value₁
, etc.meth (Xml: xml) << (Tag: string): sequence
Returns a sequence of the previous siblings of
Xml
with tagTag
.meth (Xml: xml) << (Tag: string, Attribute₁ is Value₁, ...): sequence
Returns a sequence of the previous siblings of
Xml
with tagTag
andAttribute₁ = Value₁
, etc.meth (Xml: xml) >> (Fn: function): sequence
Returns a sequence of the next siblings of
Xml
for whichFn(Child)
is non-nil.meth (Xml: xml) >> (Attribute₁ is Value₁, ...): sequence
Returns a sequence of the next siblings of
Xml
withAttribute₁ = Value₁
, etc.meth (Xml: xml) >> (Tag: string): sequence
Returns a sequence of the next siblings of
Xml
with tagTag
.meth (Xml: xml) >> (Tag: string, Attribute₁ is Value₁, ...): sequence
Returns a sequence of the next siblings of
Xml
with tagTag
andAttribute₁ = Value₁
, etc.meth (Node: xml):add_next(Other: any, ...): xml
Inserts
Other
directly afterNode
.meth (Node: xml):add_prev(Other: any, ...): xml
Inserts
Other
directly beforeNode
.meth (Node: xml):index: integer | nil
Returns the index of
Node
in its parent ornil
.meth (Xml: xml):next: xml | nil
Returns the next sibling of
Xml
ornil
.meth (Xml: xml):next(N: integer): xml | nil
Returns the
N
-th next sibling ofXml
ornil
.meth (Xml: xml):parent: xml | nil
Returnst the parent of
Xml
ornil
.meth (Xml: xml):parent(N: integer): xml | nil
Returns the
N
-th parent ofXml
ornil
.meth (Xml: xml):parent(Tag: string): xml | nil
Returns the ancestor of
Xml
with tagTag
if one exists, otherwisenil
.meth (Xml: xml):prev: xml | nil
Returnst the previous sibling of
Xml
ornil
.meth (Xml: xml):prev(N: integer): xml | nil
Returns the
N
-th previous sibling ofXml
ornil
.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 eachArgᵢ
:string
: added as child text node. Consecutive strings are added a single node.xml
: added as a child node.list
: each value must be astring
orxml
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 ofParent
.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
, includingXml
.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 ofParent
ornil
.meth (Parent: xml::element)[Attribute: string]: string | nil
Returns the value of the
Attribute
attribute ofParent
.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
toParent
and returnsParent
.meth (Parent: xml::element):put(Child: any, ...): xml
Adds
Child
toParent
.meth (Xml: xml::element):set(Attribute: string, Value: string): xml
Sets the value of attribute
Attribute
inXml
toValue
and returnsXml
.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
, addingSep
between the contents of adjacent nodes.meth (Buffer: string::buffer):append(Xml: xml::element)
Appends a string representation of
Xml
toBuffer
.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 attributesAttrᵢ = 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
whereNodeᵢ
are the nodes generated bySequence
.meth (Sequence: xml::sequence) // (Args: any, ...): sequence
Generates the sequence
Nodeᵢ // Args
whereNodeᵢ
are the nodes generated bySequence
.meth (Sequence: xml::sequence) << (Args: any, ...): sequence
Generates the sequence
Nodeᵢ << Args
whereNodeᵢ
are the nodes generated bySequence
.meth (Sequence: xml::sequence) >> (Args: any, ...): sequence
Generates the sequence
Nodeᵢ >> Args
whereNodeᵢ
are the nodes generated bySequence
.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
whereNodeᵢ
are the nodes generated bySequence
.meth (Sequence: xml::sequence):parent(Args: any, ...): sequence
Generates the sequence
Nodeᵢ ^ Args
whereNodeᵢ
are the nodes generated bySequence
.meth (Sequence: xml::sequence):prev(Args: any, ...): sequence
Generates the sequence
Nodeᵢ - Args
whereNodeᵢ
are the nodes generated bySequence
.type xml::text < xml, string
A XML text node.
meth (Xml: xml::text):text: string
Returns the text content of
Xml
.