ddn.data.xml.xpointer

XPointer Framework.

This module implements the XPointer Framework (W3C Recommendation) for addressing fragments of XML documents.

Supported pointer forms:

  • Shorthand pointers: #id — resolves to the first element with a matching id attribute
  • element() scheme: element(id), element(/1/2/3), element(id/2) — addresses elements by ID and/or child sequence numbers
  • xpointer() scheme: xpointer(XPathExpr) — evaluates an XPath 1.0 expression against the document element
  • xmlns() scheme: xmlns(prefix=uri) — binds a namespace prefix for use in subsequent xpointer() schemes

Scheme fallback: when multiple scheme parts are present, they are evaluated in order and the first one that resolves to a non-empty result wins.

Remaining limitations:

  • The xpointer() scheme evaluates XPath against the document element, not the document root node
  • The element() scheme only matches elements with an unprefixed id attribute; DTD-declared ID-type attributes are not recognized
  • `^(` and `^)` escaping in scheme data is not supported
  • Point and range semantics (point(), range(), range-to(), string-range()) are not supported and are explicitly out of scope

Reference: https://www.w3.org/TR/xptr-framework/

Types 3

XPointer kind.

SHORTHANDShorthand pointer of the form `#id`.
ELEMENT`element()` scheme: addresses elements by ID or child sequence.
XPOINTER`xpointer()` scheme: evaluates an XPath 1.0 expression.
XMLNS`xmlns()` scheme: binds a namespace prefix for subsequent schemes.

A single part of an XPointer (either a scheme or a shorthand).

Fields are used depending on kind:

  • SHORTHAND: id
  • ELEMENT: elementId, elementAbsolute, elementSequence
  • XPOINTER: xpath
  • XMLNS: xmlnsPrefix, xmlnsUri
Fields
string id
string elementId
bool elementAbsolute
size_t[] elementSequence
string xpath
string xmlnsPrefix
string xmlnsUri
structXPointer

Parsed XPointer.

Fields
XPointerPart[] partsPointer parts in order.
Methods
XPointer parse(string value) static @safeParses a pointer string.
XmlNode[] evaluate(XmlDocument doc, Options options = Options.init) @safeEvaluates this pointer against a document.
Nested Templates
OptionsEvaluation strictness options.

Functions 4

private fnXmlNode[] evaluateElementScheme(XmlElement root, const ref XPointerPart part) @safe
private fnsize_t[] parseElementSequence(string s) @safe
private fnXmlElement nthChildElement(XmlElement parent, size_t index1) @safe nothrow
private fnXmlElement findById(XmlElement root, string id) @safe