A lightweight handle to a single node in an XML DOM tree.
Nodes remain valid as long as their owning XmlDocument is alive.
Reading .name, .type, or .value uses __index and does not
require a method call.
@eryx/data/xml ModuleXML module – DOM parsing, manipulation, serialisation and XPath queries.
Backed by pugixml. Provides two core types:
This module is a typed facade over an optional pugixml backend. In
builds without XML support, require("@eryx/xml") fails immediately
with a clear capability error.
local xml = require("xml")
local doc = xml.parse('<root><item id="1">Hello</item></root>')
local root = doc:root()
print(root.name) --> "root"
print(root:child("item"):text()) --> "Hello"
print(root:child("item"):attr("id")) --> "1"
-- XPath
for _, node in doc:xpath("//item[@id]") do
print(node.name, node:attr("id"))
end
A lightweight handle to a single node in an XML DOM tree.
Nodes remain valid as long as their owning XmlDocument is alive.
Reading .name, .type, or .value uses __index and does not
require a method call.
The element/PI tag name, or "" for text/comment nodes.
Shorthand for the first PCDATA/CDATA child's content (like Text()).
Returns the concatenated text content of this element (first PCDATA/CDATA child).
Sets the text content of this element (creates a PCDATA child if needed).
Returns a list of element children. If name is given, only children with that tag name are included.
Returns the first child element with the given tag name, or nil if not found.
Appends a new child element with the given tag name.
Prepends a new child element with the given tag name.
Removes a child by tag name or by XmlNode reference.
Returns the next sibling element. If name is given, skips siblings until one with a matching tag name is found.
Returns the previous sibling element.
Sets (or creates) the attribute name to value.
Returns all attributes as a { [name] = value } dictionary.
Evaluates an XPath expression relative to this node and returns all matching nodes.
Evaluates an XPath expression and returns the first match,
or nil. ]]
Evaluates an XPath expression that returns a scalar value (string, number, or boolean) rather than a node set.
Returns the absolute path of this node from the document root.
Uses delimiter (default "/") to separate path segments.
An XML document that owns a DOM tree.
The document is the entry point for parsing and serialisation. It exposes XPath queries directly so you don't always need to grab the root element first.
Returns the document element (the single top-level element).
Serialises the entire document to a string.
Writes the document to a file on disk.
Evaluates an XPath expression on the whole document and returns all matching nodes.
Evaluates an XPath expression and returns the first match, or nil.
Creates a new, empty XML document.
Use AppendChild() to add a root element and build the tree programmatically.
Node type string