Xml2Node¶
Wrapper around a libxml2 xmlNode pointer, providing helpers for XPath
evaluation, attribute/content access, and basic tree navigation.
Constructors¶
fromPTR¶
Create an Xml2Node from a non-null libxml2 xmlNode*.
ptrx: Nullable pointer to anXmlNode.
Raises an error if ptrx is None, otherwise stores the pointer in
ptr', assigns the underlying XmlNode to ptr, and marks the node
as allocated.
Parameters¶
- xml2doc': Xml2Doc tag
- ptrx: NullablePointer[XmlNode ref] ref
Returns¶
- Xml2Node ref^ ?
Public fields¶
var ptr': NullablePointer[XmlNode ref] ref¶
var ptr: XmlNode ref¶
var xml2doc: Xml2Doc tag¶
Public Functions¶
xpathEval¶
Evaluate an XPath expression relative to this node as the context node.
xpath: The XPath expression to evaluate.namespaces: Optional list of(prefix, uri)pairs to register on a temporary XPath context before evaluation.
Internally, creates a new xmlXPathContext for the owning document,
registers the provided namespaces, sets this node as the context node,
calls xmlXPathEval, frees the context, and returns an
Xml2XPathResult for the resulting xmlXPathObject*.
fun box xpathEval(
xpath: String val,
namespaces: Array[(String val , String val)] ref = array)
: (None val | Array[Xml2Node ref] ref | Bool val |
String val | F64 val)
Parameters¶
Returns¶
xpathEvalNodes¶
A convenience method that calls xpathEval and returns an Array[Xml2Node].
fun box xpathEvalNodes(
xpath: String val,
namespaces: Array[(String val , String val)] ref = array)
: Array[Xml2Node ref] ref ?
Parameters¶
Returns¶
xpathEvalString¶
A convenience method that calls xpathEval and returns a String val.
fun box xpathEvalString(
xpath: String val,
namespaces: Array[(String val , String val)] ref = array)
: String val ?
Parameters¶
Returns¶
- String val ?
xpathEvalF64¶
A convenience method that calls xpathEval and returns an F64 (XML's default Number type in libxml2).
fun box xpathEvalF64(
xpath: String val,
namespaces: Array[(String val , String val)] ref = array)
: F64 val ?
Parameters¶
Returns¶
- F64 val ?
xpathEvalBool¶
A convenience method that calls xpathEval and returns a Bool.
fun box xpathEvalBool(
xpath: String val,
namespaces: Array[(String val , String val)] ref = array)
: Bool val ?
Parameters¶
Returns¶
- Bool val ?
name¶
Return this node’s name as a Pony String.
The name is obtained from the underlying xmlNode->name C string and
cloned into a Pony-managed string.
Returns¶
- String val
getLineNo¶
Return the line number in the source document where this node was parsed, or -1 if the information is unavailable.
This forwards to xmlGetLineNo on the underlying node.
Returns¶
- I64 val
getNodePath¶
Return an XPath-like string representing the absolute path of this node within the document tree.
This is the result of libxml2’s xmlGetNodePath helper.
Returns¶
- String val
xpathCastNodeToString¶
Cast this node to a string using libxml2’s XPath string conversion
rules (equivalent to XPath’s string() function applied to the node).
Delegates to xmlXPathCastNodeToString on the underlying node.
Returns¶
- String val
getProps¶
Returns¶
getProp¶
Get the value of an attribute on this element node.
pname: Attribute name (without any prefix/namespace handling).
Returns the attribute value string from xmlGetProp, or an empty
string if the attribute is not present.
Parameters¶
- pname: String val
Returns¶
- String val
getContent¶
Return the textual content of this node, including text from its
descendants as defined by libxml2’s xmlNodeGetContent.
Useful for retrieving the logical text value of elements or text nodes.
Returns¶
- String val
getLang¶
Return the xml:lang value in scope for this node.
This consults the node and its ancestors using xmlNodeGetLang.
Returns¶
- String val
getChildren¶
Return all child element nodes of this node as an array of
Xml2Node.
Uses xmlChildElementCount, xmlFirstElementChild, and
xmlNextElementSibling to iterate only over element children, skipping
text, comments, and other non-element node types. If there are no
element children, returns an empty array.
Returns¶
setProp¶
Creates or Sets a property value (think XML Attribute) on this node.
Parameters¶
Returns¶
- None val
unsetProp¶
Unsets a property (think XML Attribute) on this node.
Parameters¶
- pname: String val
Returns¶
- None val
nodeDump¶
Serialize this node and its subtree to a string using libxml2's
xmlNodeDump.
plevel: Indentation level to start from when pretty-printing.pformat: Non-zero to enable formatted (indented) output, zero for unformatted.
Internally, creates a temporary xmlBuffer, dumps the node into it, and
returns the buffer's contents as a Pony String.
Parameters¶
Returns¶
- String val
appendChild¶
Add a child node to this element.
child: Node to add as child
Returns the added child node. The child is added at the end of the children list. Raises error if the operation fails.
Example:
let parent = doc.createElement("parent")?
let child = doc.createElement("child")?
parent.appendChild(child)?
Parameters¶
- child: Xml2Node ref
Returns¶
- Xml2Node ref ?
setContent¶
Set the text content of this node.
content: Text content to set
Replaces any existing content of the node. For elements with children, this will replace all children with a single text node.
Example:
Parameters¶
- content: String val
Returns¶
- None val
addChild¶
Convenience method to create and add a child element in one step.
child_name: Element name for the new childcontent: Optional text content
Creates a new child element, adds it to this node, and returns the new child wrapped as Xml2Node.
Example:
let doc = Xml2Doc.createWithRoot("root")?
let root = doc.getRootElement()?
let child1 = root.addChild("item", "Hello")?
let child2 = root.addChild("item", "World")?
child1.setProp("id", "1")
child2.setProp("id", "2")
Parameters¶
Returns¶
- Xml2Node ref ?