Larger, smaller, and equal string in XmlDocument

I am trying to do string comparisons in an XmlDocument, and here is what I tried. I am wondering why the first 2 give the correct result, and the last 2 do not return any result.

What I was trying to do was filter out the nodes based on the datetime string. As the last example that I have.

thanks,

XmlNodeList test = x2PathDoc.SelectNodes("//config /pendingversion [@versionconfigid > 1002002]"); XmlNodeList test2 = x2PathDoc.SelectNodes("//config /pendingversion [@versionconfigid >'1002002']"); XmlNodeList test3 = x2PathDoc.SelectNodes("//config /pendingversion[@test > 'b']"); XmlNodeList test4 = x2PathDoc.SelectNodes("//config /pendingversion [@deploydatetime > '2010-12-19T03:25:00-08:00']"); 
+2
source share
1 answer

In XPath 1.0, a comparison operator other than equality comparison works only for numbers. This is because in XML you are dealing with UNICODE. Thus, to make a string a fully ordered data type, you need the concept of mappings, which was added in XPath 2.0.

The first expression is obviusly correct. Why does the second work? Because the more than operator passes both arguments using the number() function.

From http://www.w3.org/TR/xpath/#booleans

First, comparisons that include node sets are defined in terms of comparisons that are not related to node sets; it is determined evenly for = ,! =, <=, <,> = and>.

And after describing the existing comparison for the node sets (the comparison is true only if there is a node in the node set for which the comparison is performed):

If there is no object to compare, a node-set and the operator <= , < , >= or > , then the objects are compared by converting both objects to numbers and comparing numbers in accordance with IEEE 754

+5
source

Source: https://habr.com/ru/post/1337983/


All Articles