Ox adapter

Overview

Ox is the fastest XML parser available for Ruby, providing excellent performance for simple to moderately complex XML documents.

Best for:

  • Maximum parsing speed

  • Simple document structures

  • Memory-constrained environments

  • When XPath usage is minimal

Specific adapter limitations

Ox adapter

XPath limitations

The Ox adapter uses a custom "XPath-to-locate" translation engine.

The following XPath features are NOT supported:

  • Attribute value predicates: //book[@id='123']

  • Logical operators: //book[@id and @title]

  • Position predicates: //book[1], //book[last()]

  • Text predicates: //book[text()='Title']

  • Namespace queries: //ns:element

  • Parent axis: //child/..

  • Sibling axes: following-sibling::*

  • XPath functions: count(), concat(), etc. ❌

Workaround: Use Ruby enumerable methods after basic queries:

# Instead of: doc.xpath("//book[@id='123']")
# Use:
doc.xpath("//book").find { |book| book["id"] == "123" }
For complete XPath 1.0 specification with zero limitations today, use Nokogiri or Oga adapters.

Element Ordering in Round-Trip Tests

Round-trip tests for Ox are experimental

Ox round-trip tests (nokogiri-ox CI job) are experimental because Ox lacks full XML conformance:

  • Namespace support: Ox does not properly handle namespaced elements in XPath queries

  • XPath limitations: Uses locate() instead of standard XPath; no attribute value predicates, no logical operators, no position predicates

  • Element ordering: Ox produces elements in a different order than Nokogiri/Oga for certain complex fixtures

For production use with complex XML, prefer Nokogiri or Oga adapters.

The Ox adapter produces elements in a different order than other adapters for certain fixtures with complex nested structures. In round-trip tests, this causes the elements_with_attributes array length comparison to fail, even though the semantic equivalence check (double round-trip) passes.

Known affected fixtures:

  • niso-jats/element_citation.xml

  • niso-jats/pnas_sample.xml

  • metanorma/collection1nested.xml

This is a known limitation tracked in the round-trip test suite via KNOWN_ELEMENT_ORDERING_ISSUES. The elements_with_attributes comparison is automatically skipped for these Ox adapter pairs.

See also: