Xpath在“ MSXML2.DOMDocument”上工作。但不在“ MSXML2.DOMDocument60”上 [英] Xpath works on "MSXML2.DOMDocument" but not on "MSXML2.DOMDocument60"

查看:79
本文介绍了Xpath在“ MSXML2.DOMDocument”上工作。但不在“ MSXML2.DOMDocument60”上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在XmlDocument中的字符串比较大,更少和相等


在VBA中,我有以下表达式:

Hi, In VBA I have the folowing expression:

 SourceXml.selectNodes("//Races/Race[/FirstRun[@ActStart>'2011-03-01' or
 @ActEnd<'2011-03-15']]")

如果我将SourceXml定义为MSXML2.DOMDocument,它将检索具有所需节点的列表。
如果我将SourceXml定义为MSXML2.DOMDocument60,它将检索一个内部包含0个元素的列表。

If I define the SourceXml as MSXML2.DOMDocument it retrieves a list with the desired nodes. If I define the SourceXml as MSXML2.DOMDocument60 it retrieves a list with 0 elements inside.

Xpath表达式有什么问题?

Whath is wrong with the Xpath expression?

推荐答案

您提供的表达式

//Races/Race[/FirstRun[@ActStart>'2011-03-01' or  ActEnd<'2011-03-15']]

将不会选择任何节点,因为在XPath 1.0中没有> < 字符串的比较运算符(仅用于数字)。上面的两个字符串首先转换为数字,其结果为 NaN ,任何涉及 NaN 的比较结果均为 false()。因此,谓词的值是 false(),表达式不选择任何节点。

will not select any node, because in XPath 1.0 there are no > or < comparison operators for strings (only for numbers). The two strings above are first converted to numbers, which yields NaN and any comparison involving NaN is false(). Therefore, the value of the predicate is false() and the expression doesn't select any node.

使用 MSXML2.DOMDocument.SelectNodes()选择节点的事实是因为在此早期版本的MSXML中,默认选择语言不是XPath ,而是一种称为 XSL(如果我还记得的话),它不是标准的W3C XPath语言。

The fact that using MSXML2.DOMDocument.SelectNodes() selects nodes is because in this early version of MSXML the default selection language is not XPath but something called "XSL" (if I remember well) and it is not the standard, W3C XPath language.

我想MSXML6不再提供这种过时的方言。

I guess that MSXML6 no longer provides this obsolete dialect.

您可能会成功使用此XPath表达式

//Races/Race[/FirstRun
              [translate(@ActStart,'-','') > 20110301 
             or
               translate(ActEnd, '-','') < 20110315
              ]
            ]

这篇关于Xpath在“ MSXML2.DOMDocument”上工作。但不在“ MSXML2.DOMDocument60”上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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