字符串更大,更小,并享有平等的XmlDocument的比较 [英] String greater, less, and equal comparison in XmlDocument

查看:124
本文介绍了字符串更大,更小,并享有平等的XmlDocument的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个XmlDocument的字符串比较,而下面是我试过。我想知道为什么第2产生正确的结果,最后2不返回任何结果。

我试图做的是过滤掉根据日期时间字符串节点。就像最后一个例子,我有。

感谢

  XmlNodeList中测试= x2PathDoc.SelectNodes(//配置
                                            / pendingversion
                                              [@versionconfigid> 1002002]);

XmlNodeList中测试2 = x2PathDoc.SelectNodes(//配置
                                             / pendingversion
                                               [@versionconfigid>'1002002']);

XmlNodeList中TEST3 = x2PathDoc.SelectNodes(//配置
                                             / pendingversion [@test> 'B']);

XmlNodeList中TEST4 = x2PathDoc.SelectNodes(//配置
                                             / pendingversion
                                               [@deploydatetime>
                                                '2010-12-19T03:25:00-08:00']);
 

解决方案

在XPath 1.0中,比较操作比相等比较等,对数字才起作用。这是因为在XML你正在处理的UNI code。所以,为了使弦一个完整的有序数据类型,需要的归类,它的加入的XPath 2.0的概念

第一八佰伴pression是obviusly权。为什么第二部作品?因为大于运算符铸两个参数与号()功能。

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

  

首先,涉及的比较   节点集在来定义   比较不涉及   节点集;这是统一定义   为=,=,<!=,<,> =和>

和描述existencial比较节点集(一个比较唯一真正的,如果有在为至极的比较设置节点一个节点真)后:

  

当被比较的对象都不是   节点集和运算符是< = < ,   > = > ,那么对象通过将两个对象为数字相比,   和比较所述数字根据   IEEE 754

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

这篇关于字符串更大,更小,并享有平等的XmlDocument的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆