ddn.data.xml.xpath
XPath 1.0 engine.
This module provides XPath 1.0 expression parsing, evaluation, and value types with conversion rules.
Supported features:
- All 13 XPath 1.0 axes except
namespace(the DOM does not model namespace declarations as distinct nodes) - Node tests:
name, ``,node(),text(),comment(),processing-instruction() - Predicates: numeric, boolean, and expression predicates
- Full operator set: boolean (
and,or), comparison (`=`, `!=`, `<`, `>`, `<=`, `>=`), arithmetic (`+`, `-`, ``,div,mod), union (`|`) - Core function library:
last,position,count,id,string,concat,starts-with,contains,substring,substring-before,substring-after,string-length,normalize-space,translate,boolean,not,true,false,name,local-name,namespace-uri,number,sum,floor,ceiling,round,lang - Namespace-aware name matching via
XPathNamespaceResolver
Remaining limitations:
- The
namespaceaxis is not supported (no DOM namespace-node type) processing-instruction()literal argument (e.g.processing-instruction('xml-stylesheet')) is not supportedid()only matches elements with an unprefixedidattribute; DTD-declared ID-type attributes are not recognized- String functions operate on UTF-8 code units rather than Unicode code points;
string-length()andsubstring()may produce incorrect results for multi-byte characters - Number formatting may use scientific notation for very large/small values
It is intentionally separate from the legacy/minimal ddn.data.xml.query module.
iface XPathNamespaceResolver
Types 8
enumXPathValueKind
XPath value kind.
NODESETNode-set value.
STRINGString value.
NUMBERNumber value (IEEE double).
BOOLEANBoolean value.
enumXPathAxis
XPath axis.
All XPath 1.0 axes are defined except namespace, which is intentionally omitted because the DOM does not model namespace declarations as nodes.
CHILD`child::` axis.
DESCENDANT`descendant::` axis.
DESCENDANT_OR_SELF`descendant-or-self::` axis (`//`).
PARENT`parent::` axis (`..`).
SELF`self::` axis (`.`).
ATTRIBUTE`attribute::` axis (`@`).
ANCESTOR`ancestor::` axis.
ANCESTOR_OR_SELF`ancestor-or-self::` axis.
FOLLOWING_SIBLING`following-sibling::` axis.
PRECEDING_SIBLING`preceding-sibling::` axis.
FOLLOWING`following::` axis.
PRECEDING`preceding::` axis.
XPath node test kind.
NAMEMatch by name.
ANY`*` wildcard.
NODE`node()`
TEXT`text()`
COMMENT`comment()`
PROCESSING_INSTRUCTION`processing-instruction()`
structXPathStep
A single path step.
structXPathExpression
A parsed XPath expression (subset).
Fields
string expressionOriginal expression string.bool absoluteIf `true`, expression is absolute (starts with `/` or `//`).Methods
XmlNode[] select(XmlNode context, XPathNamespaceResolver resolver = null) @safeSelects nodes under `context`.interfaceXPathNamespaceResolver
Namespace resolver for XPath evaluation.
Implementations map an XPath prefix to a namespace URI.
Methods
Simple map-backed namespace resolver.
Methods
Constructors
this(string[string] mappings)Constructs the resolver.structXPathValue
An XPath value (node-set, string, number, or boolean).
Fields
XPathValueKind kindValue kind discriminator.Methods
Functions 1
fn
XPathValue evaluateXPath(string expression, XmlNode context, XPathNamespaceResolver resolver = null) @safeEvaluates an XPath expression as an `XPathValue`.