Class: Canon::Xml::XPathEngine
- Inherits:
-
Object
- Object
- Canon::Xml::XPathEngine
- Defined in:
- lib/canon/xml/xpath_engine.rb
Overview
XPath evaluation engine for C14N subset selection.
Supports a focused subset of XPath 1.0 sufficient for W3C C14N subset canonicalization:
-
Absolute paths: /root/child, /root/child
-
Descendant-or-self: //element, //ns:element
-
Predicates: [1] (position), [@attr], [@attr=‘value’]
-
Wildcards: *
-
Union: expr1 | expr2
Not supported (not needed for C14N subset):
-
Axes other than child and descendant-or-self
-
Functions (last(), position(), etc.)
-
Variables
Class Method Summary collapse
-
.evaluate(root, xpath) ⇒ Array<Node>
Evaluate an XPath expression against a data model tree.
Instance Method Summary collapse
-
#evaluate(xpath) ⇒ Array<Node>
Evaluate an XPath expression and return matched nodes.
-
#initialize(root) ⇒ XPathEngine
constructor
A new instance of XPathEngine.
Constructor Details
#initialize(root) ⇒ XPathEngine
Returns a new instance of XPathEngine.
31 32 33 |
# File 'lib/canon/xml/xpath_engine.rb', line 31 def initialize(root) @root = root end |
Class Method Details
Instance Method Details
#evaluate(xpath) ⇒ Array<Node>
Evaluate an XPath expression and return matched nodes.
39 40 41 42 43 44 45 46 |
# File 'lib/canon/xml/xpath_engine.rb', line 39 def evaluate(xpath) # Handle union operator (|) if xpath.include?("|") xpath.split("|").flat_map { |expr| evaluate(expr.strip) }.uniq else evaluate_path(xpath.strip) end end |