Thanks to visit codestin.com
Credit goes to github.com

Skip to content

XPath: Node-Set to Boolean  #17

@mirko314

Description

@mirko314

Hi,

I think I found an issue with the XPath evaluation of REXML, as I am currently comparing multiple XPath libraries.

If we pass an XPath expression to REXML which should evaluate a condition on nodes, it evaluates it on every node. While this may seem intuitve, it differs from the XPath 1.0 Standard, as it states there:

If one object to be compared is a node-set and the other is a number, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the number to be compared and on the result of converting the string-value of that node to a number using the number function is true.
(Source: https://www.w3.org/TR/1999/REC-xpath-19991116/ Chapter 3.4 Booleans)

Below is a simple demonstration example tested on ruby 2.6. The output is falsetruetruefalse

require "rexml/document"
include REXML
string = <<EOF
  <?xml version="1.0"?>
  <bookstore>
      <price>123</price>
      <price>456</price>
      <price>789</price>
      <price>234</price>
  </bookstore>
EOF
doc = Document.new string
puts XPath.match( doc, "//price>400")

This is significantly different from the other libraries I investigated:

Testing library: nokogiri , xpath: //price>400
true
Testing library: xqilla , xpath: //price>400
true
Testing library: rexml , xpath: //price>400
falsetruetruefalse
Testing library: xalan-j , xpath: //price>400
true
Testing library: saxon , xpath: //price>400
true
Testing library: jaxen , xpath: //price>400
true
Testing library: lxml , xpath: //price>400
true
Testing library: VTD-Gen , xpath: //price>400
true

Basically I think to fix this, a further evaluation step is needed. Instead of returning the Results of the comparison directly, it should be evaluated if one of the results is true and then just return true.

I hope this helps and best regards,
Mirko

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions