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.
class XPathBinaryExpr XPathFunctionCallExpr XPathLiteralExpr XPathMapNamespaceResolver XPathPathExpr XPathUnaryMinusExpr
fn appendAxisResults appendDescendantsOrSelf applyPredicates axisFromName childIndex collectDescendantText collectDocumentOrder collectIdTokens compareDocumentOrder compareValues consumeCall dedupeInDocumentOrder dedupeInOrder evaluateFunctionExpr evaluatePredicate evaluateXPath formatXPathNumber indexOfNode isAncestorOf isNameChar isNameStartChar matchesTest matchKeyword nodesetStringValue nodeStringValue objectIdentityKey parseInto parseXPathNumber readNameToken rootOf skipWs sortInDocumentOrder splitQName
Types 16
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()`
Methods
XPathValue evaluate(XmlNode context, XPathNamespaceResolver resolver, size_t position, size_t last) @safeFields
private XPathValue _valMethods
XPathValue evaluate(XmlNode context, XPathNamespaceResolver resolver, size_t position, size_t last) @safeConstructors
this(XPathValue val)Fields
private XPathExpression _pathMethods
XPathValue evaluate(XmlNode context, XPathNamespaceResolver resolver, size_t position, size_t last) @safeConstructors
this(XPathExpression path)Fields
private IXPathExpr _exprMethods
XPathValue evaluate(XmlNode context, XPathNamespaceResolver resolver, size_t position, size_t last) @safeConstructors
this(IXPathExpr expr)OR
AND
EQ
NEQ
LT
GT
LTE
GTE
PLUS
MINUS
MUL
DIV
MOD
UNION
Methods
XPathValue evaluate(XmlNode context, XPathNamespaceResolver resolver, size_t position, size_t last) @safeConstructors
this(IXPathExpr left, IXPathExpr right, XPathBinaryOp op)Methods
XPathValue evaluate(XmlNode context, XPathNamespaceResolver resolver, size_t position, size_t last) @safeConstructors
this(string name, IXPathExpr[] args)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 `//`).private XPathStep[] _stepsMethods
XmlNode[] select(XmlNode context, XPathNamespaceResolver resolver = null) @safeSelects nodes under `context`.XmlNode[] evaluatePath(XmlNode context, XPathNamespaceResolver resolver) @safeFields
string ssize_t iMethods
IXPathExpr parseExpr() @safeinterfaceXPathNamespaceResolver
Namespace resolver for XPath evaluation.
Implementations map an XPath prefix to a namespace URI.
Methods
Simple map-backed namespace resolver.
Fields
private string[string] _mapMethods
Constructors
this(string[string] mappings)Constructs the resolver.structXPathValue
An XPath value (node-set, string, number, or boolean).
Fields
XPathValueKind kindValue kind discriminator.private XmlNode[] _nodesprivate string _stringprivate double _numberprivate bool _boolMethods
Functions 33
fn
XPathValue evaluateXPath(string expression, XmlNode context, XPathNamespaceResolver resolver = null) @safeEvaluates an XPath expression as an `XPathValue`.private fn
void appendAxisResults(
ref XmlNode[] sink,
XmlNode node,
const ref XPathStep step,
XPathNamespaceResolver resolver) @safeprivate fn
void appendDescendantsOrSelf(
ref XmlNode[] sink,
XmlNode node,
const ref XPathStep step,
XPathNamespaceResolver resolver) @safeprivate fn
bool matchesTest(XmlNode node, const ref XPathStep step, XPathNamespaceResolver resolver) @safeprivate fn
XmlNode[] applyPredicates(XmlNode[] nodes, IXPathExpr[] preds, XPathNamespaceResolver resolver) @safeprivate fn
bool evaluatePredicate(IXPathExpr pred, XmlNode node, size_t position, size_t last, XPathNamespaceResolver resolver) @safeprivate fn
XPathValue evaluateFunctionExpr(
string name,
IXPathExpr[] args,
XmlNode context,
XPathNamespaceResolver resolver,
size_t position,
size_t last) @safeprivate fn
void collectDescendantText(ref typeof(appender!string()) sink, const(XmlParentNode) n) @safe