Skip to main content

Module types

Module types 

Source
Expand description

XPath 1.0 Runtime Types (§25).

Internal Rust representation of XPath values: node-sets, strings, numbers, booleans, and conversions between them.

§UPSTREAM-PARITY

XPath 1.0 type system with exact IEEE 754 floating-point semantics: NaN, infinity, negative zero, rounding behavior.

§Courts

XPATH-TYPES-*

§Upstream contract

Mirrors the value model of upstream xpath.c / xpathInternals.h (SRC-LIBXML2-2.15.0-XPATH-C, parity target libxml2 2.15.3 oracle): xmlXPathObject types (XPATH_NODESET, XPATH_BOOLEAN, XPATH_NUMBER, XPATH_STRING, XPATH_POINT/RANGE/LOCATIONSET, XPATH_USERS, XPATH_XSLT_TREE) and the string/number conversion functions xmlXPathCastToString, xmlXPathStringEvalNumber and xmlXPathCastNumberToString.

§Conceptual behavior

Defines the runtime value types and their conversions. Node-sets are ordered, deduplicated collections of borrowed document nodes; node_string_value computes the XPath string-value of a node (R-000114 fixed the empty attribute string-value); string_bytes_to_ number / number_to_string are faithful ports of the R-000166 number conversion with the 1e9/1e-5 scientific threshold and DBL_DIG=15 fraction digits.

§Ownership & safety invariants

XPathNode holds a raw *mut _xmlNode that is borrowed from the document — the tree must outlive evaluation (SAFETY note on the struct). Values own their storage (String/NodeSet) and are freed by drop; nothing here allocates through the C allocator except the exports bridge.

§Historical quirks & epochs

The conversion rules track the 2.15.3 oracle epoch: the E-001 newline-separated node-set dump (commit da35eeae, 2.9.10) is the output epoch the XPath CLI surfaces target, and number formatting (R-000166, 967/967 number() corpus) is fixed since the same era.

§Deliberate oddities

-0.0 serializes as 0, NaN as NaN, infinities as Infinity/ -Infinity, and integral values take the integer shortcut — the upstream xmlXPathFormatNumber quirks reproduced instead of Rust Display.

§Proving courts

XPATH-TYPES-* differential probes and the 967/967 number() corpus compare conversions byte-identical against the oracle; cargo test runs the conversion unit suites (incl. test_number_to_string).

§Tempting simplifications that would break parity

Do not switch conversions to Rust std float formatting or parsing: the oracle digit accumulation (MAX_FRAC=20), exponent underflow (5e-324 → 0), threshold selection and exponent padding are observable (R-000166). Do not make node-sets own the tree: callers free the document independently of the XPath object.

Structs§

NodeSet
An XPath node-set.
XPathNode
A node in a node-set, identified by pointer.

Enums§

XPathType
XPath type.
XPathValue
XPath runtime value.

Functions§

compare_document_order
Compare two nodes in document order.
node_string_value
Get the string value of a node (XPath 1.0 §5.1).
number_to_string
Convert a number to a string (XPath 1.0 §4.7.2) — a faithful port of upstream xmlXPathCastNumberToString / xmlXPathFormatNumber (xpath.c, R-000166): the integer shortcut, the 1e9/1e-5 scientific threshold, and the DBL_DIG=15 fraction-digit computation reproduce the oracle’s exact digits, including exponent formatting (e+20, e-05) and trailing-zero trimming.
string_bytes_to_number
Port of upstream xpath.c xmlXPathStringEvalNumber (R-000166): the oracle accumulates digits directly (ret = ret * 10 + d), caps the fraction at MAX_FRAC=20 digits after any leading zeros, applies the exponent with pow(10.0, exp) (underflowing to 0 below the smallest subnormal, e.g. 5e-324), accepts XML whitespace around the number, and returns NaN for anything else — including a leading ‘+’.
string_to_number
Convert a string to a number (XPath 1.0 §4.7.1) — upstream xmlXPathStringEvalNumber semantics.