XmlDocument 中的字符串大于、小于和等于比较

发布于 2024-10-07 21:25:37 字数 944 浏览 0 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

茶花眉 2024-10-14 21:25:37

在 XPath 1.0 中,除相等比较之外的比较运算符仅适用于数字。这是因为在 XML 中您处理的是 UNICODE。因此,为了使 string 成为完整的有序数据类型,您需要 XPath 2.0 中添加的排序规则概念。

第一个表达显然是正确的。为什么第二个有效?因为“大于”运算符使用 number() 函数强制转换两个参数。

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

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

在描述了节点集的存在比较之后(仅当节点集中存在一个比较为真的节点时,比较才为真):

当要比较的对象都不是
节点集,运算符为 <=<
>=>,然后通过将两个对象都转换为数字来比较对象
并根据以下数字进行比较
IEEE 754

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文