Mica::XML::Node
A node of a Mica::XML::Document: an element, attribute, text, CDATA
section, comment, processing instruction, DOCTYPE, entity reference or
the document itself.
Node is a struct holding its document and an index, so it is cheap to
pass around and two Node values for the same node compare equal. The
API mirrors stdlib XML::Node.
Instance methods
Sets attribute name to value, adding it when missing. A number or
Bool is written with to_s (at most a few dozen bytes).
Returns the value of attribute name (matched by qualified name, then by local name), or nil.
Returns the text content: the concatenated text of all descendant text and CDATA nodes for elements and the document; the value for other nodes.
Sets the content. For an element this replaces its children with one text node holding text (escaped on output, never parsed as markup).
Removes attribute name and returns its value, or nil when missing.
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
Returns the node's name: the local name for elements and attributes
(as in stdlib), the target for PIs, the name for entity references and
the DOCTYPE; "text", "#cdata-section", "comment" or
"document" otherwise.
Renames an element, attribute or PI. A prefixed name is resolved against the namespace declarations in scope.
Raises Mica::Error for an invalid name or an unbound prefix.
Returns the namespace of an element or attribute, or nil when it is in no namespace.
Returns the namespaces in scope on this node: its own declarations and its ancestors', the innermost declaration of each prefix winning.
Returns the namespaces in scope as "xmlns:prefix" => uri (and
"xmlns" => uri for the default namespace), like stdlib.
Returns the parent node (the owning element for attributes), or nil for the document and for unlinked nodes.
Returns the qualified name (prefix:local) of an element or
attribute; the same as name for other nodes.
Serializes this node as XML. With indent above 0, elements whose children are all elements, comments or PIs are indented (mixed content is written as is, like libxml2's format mode).
Serializes this node as XML. With indent above 0, elements whose children are all elements, comments or PIs are indented (mixed content is written as is, like libxml2's format mode).
Detaches this node (and its subtree) from the document tree. The node stays usable on its own.
Raises Mica::Error when this node is a namespace declaration that a
name in its element's subtree still resolves through.
Evaluates XPath path with this node as the context node. Returns a
NodeSet, String, Float64 or Bool.
namespaces maps prefixes to URIs. Without it, the namespaces declared
on the root element are registered (the default namespace under the
prefix xmlns), like stdlib. variables binds $name references.
The evaluation runs under budget, or draws on meter when given
(see XPath::Expression#evaluate).
Raises Mica::XML::XPathError on a syntax error or an unsupported
feature, and Mica::LimitExceededError when the budget or deadline
runs out.
Evaluates path and converts the result to a boolean.
Evaluates path and converts the result to a number.
Evaluates path and returns the first node, or nil.
Evaluates path and returns the resulting node set. Raises
Mica::XML::XPathError when the result is not a node set.
Evaluates path and converts the result to a string (XPath string()
rules: a node set gives its first node's string value).