Quantcast

Bug? - Problem with comparing numerical values:

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Bug? - Problem with comparing numerical values:

Wolfgang May
Dear all,

I have an XML case where numeric values are not always perfectly formatted.
As far as I understand, numeric comparisons in XPath filters should nevertheless
work - but they don't (saxon 9.7.0.7).

Small Example:

let $ex :=
  <bla><n>10</n>
       <n>123</n>
       <n> 1234 </n>
       <n>
          1234
       </n>
       <n>12345</n>
  </bla>
return
 $ex[n>1000]

(both of the 1234 yield the same problem):

* java.lang.NumberFormatException: For input string: " 1234 "
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Long.parseLong(Long.java:430)
        at java.lang.Long.parseLong(Long.java:483)
        at net.sf.saxon.expr.GeneralComparison.quickCompare(GeneralComparison.java:1013)
        at net.sf.saxon.expr.GeneralComparison.compare(GeneralComparison.java:797)
* with "return $ex[n>10000]" instead, it works, although it must also compare the 1234 items.
* with "return $ex[n/number()>1000]" it also works.
  Shouldn't that be also done implicitly in the same way for [n>1000]?


Note: saxon (EE) considers the XML fragment to be valid (i.e., accept
these values as integers) wrt. the following XSD:

#########
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="bla">
  <xs:complexType>
   <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="unbounded" ref="n"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>

 <xs:element name="n">
  <xs:complexType>
   <xs:simpleContent>
    <xs:extension base="xs:nonNegativeInteger">
    </xs:extension>
   </xs:simpleContent>
  </xs:complexType>
 </xs:element>
</xs:schema>
###########

Mit freundlichen Gruessen/Best regards,
Wolfgang May

--
Prof. Dr. Wolfgang May      E-mail: [hidden email]  
Universitaet Goettingen     http://user.informatik.uni-goettingen.de/~may
Institut fuer Informatik    
Goldschmidtstrasse 7        D-37077 Goettingen / Germany
Tel ++49 (0)551 39-17-2021  Fax ++49 (0)551 39-14415

------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Bug? - Problem with comparing numerical values:

Michael Kay
Thanks for pointing it out.

QuickCompare is a fast path for numeric comparisons where we check whether a value is plausibly within some range without actually doing the full conversion from string to number. It looks as if we missed the whitespace complications.

Logged here: https://saxonica.plan.io/issues/2882

Michael Kay
Saxonica

> On 17 Aug 2016, at 14:57, Wolfgang May <[hidden email]> wrote:
>
> Dear all,
>
> I have an XML case where numeric values are not always perfectly formatted.
> As far as I understand, numeric comparisons in XPath filters should nevertheless
> work - but they don't (saxon 9.7.0.7).
>
> Small Example:
>
> let $ex :=
>  <bla><n>10</n>
>       <n>123</n>
>       <n> 1234 </n>
>       <n>
>          1234
>       </n>
>       <n>12345</n>
>  </bla>
> return
> $ex[n>1000]
>
> (both of the 1234 yield the same problem):
>
> * java.lang.NumberFormatException: For input string: " 1234 "
>        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
>        at java.lang.Long.parseLong(Long.java:430)
>        at java.lang.Long.parseLong(Long.java:483)
>        at net.sf.saxon.expr.GeneralComparison.quickCompare(GeneralComparison.java:1013)
>        at net.sf.saxon.expr.GeneralComparison.compare(GeneralComparison.java:797)
> * with "return $ex[n>10000]" instead, it works, although it must also compare the 1234 items.
> * with "return $ex[n/number()>1000]" it also works.
>  Shouldn't that be also done implicitly in the same way for [n>1000]?
>
>
> Note: saxon (EE) considers the XML fragment to be valid (i.e., accept
> these values as integers) wrt. the following XSD:
>
> #########
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:element name="bla">
>  <xs:complexType>
>   <xs:sequence>
>    <xs:element minOccurs="0" maxOccurs="unbounded" ref="n"/>
>   </xs:sequence>
>  </xs:complexType>
> </xs:element>
>
> <xs:element name="n">
>  <xs:complexType>
>   <xs:simpleContent>
>    <xs:extension base="xs:nonNegativeInteger">
>    </xs:extension>
>   </xs:simpleContent>
>  </xs:complexType>
> </xs:element>
> </xs:schema>
> ###########
>
> Mit freundlichen Gruessen/Best regards,
> Wolfgang May
>
> --
> Prof. Dr. Wolfgang May      E-mail: [hidden email]  
> Universitaet Goettingen     http://user.informatik.uni-goettingen.de/~may
> Institut fuer Informatik    
> Goldschmidtstrasse 7        D-37077 Goettingen / Germany
> Tel ++49 (0)551 39-17-2021  Fax ++49 (0)551 39-14415
>
> ------------------------------------------------------------------------------
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 



------------------------------------------------------------------------------
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...