XmlDocument 中的字符串大于、小于和等于比较
我正在尝试在 XmlDocument 中进行字符串比较,以下是我尝试过的。我想知道为什么前 2 个产生正确的结果,而后 2 个不返回任何结果。
我试图做的是根据日期时间字符串过滤掉节点。就像我最后一个例子一样。
谢谢,
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']");
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']");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 XPath 1.0 中,除相等比较之外的比较运算符仅适用于数字。这是因为在 XML 中您处理的是 UNICODE。因此,为了使 string 成为完整的有序数据类型,您需要 XPath 2.0 中添加的排序规则概念。
第一个表达显然是正确的。为什么第二个有效?因为“大于”运算符使用
number()
函数强制转换两个参数。来自 http://www.w3.org/TR/xpath/#booleans
在描述了节点集的存在比较之后(仅当节点集中存在一个比较为真的节点时,比较才为真):
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
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):