ddn.data.xml.query

XPath-like querying entrypoints.

Types 3

A parsed query step.

This is a minimal XPath-like model supporting:

  • child steps (a/b)
  • descendant steps (//b)
  • wildcard (`*`)
  • basic attribute predicates ([@id='x'])
Fields
bool descendantOrSelfIf `true`, this step uses descendant-or-self (`//`) instead of child (`/`).
string nameElement name to match (`*` means wildcard).
string attributeNameOptional attribute predicate name (no namespace).
string attributeValueOptional attribute predicate value (empty means only existence check).
bool hasAttributePredicateIf `true`, `attributeName`/`attributeValue` are active.
size_t indexPredicateOptional positional predicate (1-based). `0` means not present.
structXmlPath

An XPath-like query.

Fields
string expressionOriginal expression string.
private XmlQueryStep[] _steps
Methods
XmlPath parse(string expression) @safeParses a path expression.
XmlElement[] select(XmlElement root) const @safeSelects elements under `root` that match this path.
aliasselectAll = xpath

Alias for xpath to provide more traditional DOM-like naming.

Functions 7

fnXmlElement[] xpath(XmlElement root, string expression) @safeSelects elements matching an XPath-like expression under `root`.
fnNullable!XmlElement selectFirst(XmlElement root, string expression) @safeSelects the first element matching an XPath-like expression under `root`.
private fnXmlQueryStep[] parseSteps(string expression) @safe
private fnXmlQueryStep parseStep(string rawStep, bool descendant) @safe
private fnvoid parsePredicate(ref XmlQueryStep step, string pred) @safe
private fnbool matches(XmlElement el, const ref XmlQueryStep step) @safe
private fnvoid collectDescendantsOrSelf(ref XmlElement[] sink, XmlElement root, const ref XmlQueryStep step) @safe