vba Xpath 适用于“MSXML2.DOMDocument”但不适用于“MSXML2.DOMDocument60”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4865476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:36:16  来源:igfitidea点击:

Xpath works on "MSXML2.DOMDocument" but not on "MSXML2.DOMDocument60"

xmlvbaxpathdomdocument

提问by CaBieberach

Possible Duplicate:
String greater, less, and equal comparison in XmlDocument

可能的重复:
XmlDocument 中的字符串更大、更少和相等比较

Hi, In VBA I have the folowing expression:

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

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

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.

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

Whath is wrong with the Xpath expression?

Xpath 表达式有什么问题?

回答by Dimitre Novatchev

The expression you have provided:

您提供的表达式

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

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 NaNand any comparison involving NaNis false(). Therefore, the value of the predicate is false()and the expression doesn't select any node.

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

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

使用MSXML2.DOMDocument.SelectNodes()选择节点的事实是因为在这个早期版本的 MSXML 中,默认选择语言不是 XPath,而是称为“XSL”(如果我没记错的话),并且它不是标准的 W3C XPath 语言。

I guess that MSXML6 no longer provides this obsolete dialect.

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

In your case you might be able to use this XPath expression successfully:

在您的情况下,您可能能够成功使用此 XPath 表达式

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