Loose keys
XPath namespaces and variables doesn't accept symbol keys. It'll be convenient if symbol keys are accepted.
Nokogiri accepts both string and symbol keys.
namespaces = { ns: 'url' }
variables = { id: 'a' }
xml = '<foo xmlns="url"><bar id="a"/></foo>'
Nokogiri::XML.parse(xml).xpath('//ns:bar[@id=$id]', namespaces, variables)
Strict value check
XPath variables have value validation. Namespaces can also have validation
Nokogiri::XML.parse('<a/>').xpath('//a', { ns: 42 }) #=> TypeError
Strict variable existence check
There's two options
- Reference time check
- Pros: easy to implement
- Cons: error is document dependent
- Pre-check all variables in xpath
Nokogiri(libxml2) implements reference time check.
Nokogiri::XML.parse('<b/>').xpath('//a[@id=$foo]', nil, {fooo: '1'}) # => []
Nokogiri::XML.parse('<a/>').xpath('//a[@id=$foo]', nil, {fooo: '1'}) # => ERROR: Undefined variable
XPath 1.0 spec:
A VariableReference evaluates to the value to which the variable name is bound in the set of variable bindings in the context. It is an error if the variable name is not bound to any value in the set of variable bindings in the expression context.
I'm not sure whether it should be an error in evaluation context (reference-time) or in pre-check phase.
In XPath 2.0, it's explicitly defined to be a static-error, so XPath 1.0 spec might be ambiguous.
Loose keys
XPath namespaces and variables doesn't accept symbol keys. It'll be convenient if symbol keys are accepted.
Nokogiri accepts both string and symbol keys.
Strict value check
XPath variables have value validation. Namespaces can also have validation
Strict variable existence check
There's two options
Nokogiri(libxml2) implements reference time check.
XPath 1.0 spec:
I'm not sure whether it should be an error in evaluation context (reference-time) or in pre-check phase.
In XPath 2.0, it's explicitly defined to be a static-error, so XPath 1.0 spec might be ambiguous.