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 namespace axis is not supported (no DOM namespace-node type)
  • processing-instruction() literal argument (e.g. processing-instruction('xml-stylesheet')) is not supported
  • id() only matches elements with an unprefixed id attribute; DTD-declared ID-type attributes are not recognized
  • String functions operate on UTF-8 code units rather than Unicode code points; string-length() and substring() 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.

Types 8

XPath value kind.

NODESETNode-set value.
STRINGString value.
NUMBERNumber value (IEEE double).
BOOLEANBoolean value.

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.

Fields
string name
IXPathExpr[] predicates

A parsed XPath expression (subset).

Fields
string expressionOriginal expression string.
bool absoluteIf `true`, expression is absolute (starts with `/` or `//`).
Methods
XPathExpression parse(string expression) static @safeParses an XPath expression.
XmlNode[] select(XmlNode context, XPathNamespaceResolver resolver = null) @safeSelects nodes under `context`.

Namespace resolver for XPath evaluation.

Implementations map an XPath prefix to a namespace URI.

Methods
string lookupNamespaceUri(string prefix) @safe nothrow;Looks up a namespace URI for `prefix`.

Simple map-backed namespace resolver.

Methods
string lookupNamespaceUri(string prefix) @safe nothrow
Constructors
this(string[string] mappings)Constructs the resolver.

An XPath value (node-set, string, number, or boolean).

Fields
XPathValueKind kindValue kind discriminator.
Methods
XPathValue nodeset(XmlNode[] nodes) static @safeCreates a node-set value.
XPathValue string_(string value) static @safeCreates a string value.
XPathValue number(double value) static @safeCreates a number value.
XPathValue boolean(bool value) static @safeCreates a boolean value.
XmlNode[] toNodeSet() @safeReturns the value as a node-set.
bool toBoolean() const @safe nothrowConverts the value to a boolean using XPath 1.0 rules.
string toString() const @safeConverts the value to a string using XPath 1.0 rules.
double toNumber() const @safeConverts the value to a number using XPath 1.0 rules.

Functions 1

fnXPathValue evaluateXPath(string expression, XmlNode context, XPathNamespaceResolver resolver = null) @safeEvaluates an XPath expression as an `XPathValue`.