开发者

String greater, less, and equal comparison in XmlDocument

i'm trying to do a string comparison in a XmlDocument, and the following is what i tried. I am wondering why the first 2 yield the right result, and the last 2 doesn't return any result.

What i was trying to do is to filter out nodes based on a datetime string. Like the last example 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']");


In XPath 1.0, comparison operator other than equality comparison, works only for numbers. This is because in XML you are dealing with UNICODE. So, in order to make string a complete ordered data type, you need the notion of collations that it was added in XPath 2.0.

The first expression is obviusly right. Why the second works? Because "greater than" operator cast both arguments with number() function.

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

First, comparisons that involve node-sets are defined in terms of comparisons that do not involve node-sets; this is defined uniformly for =, !=, <=, <, >= and >.

And after describing the existencial comparison for node sets (a comparison is true only if there is a node in the node set for wich the comparison is true):

When neither object to be compared is a node-set and the operator is <=, <, >= or >, then the objects are compared by converting both objects to numbers and comparing the numbers according to IEEE 754

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜