开发者

Xpath works on "MSXML2.DOMDocument" but not on "MSXML2.DOMDocument60" [duplicate]

This question already has an answer here: Closed 12 years ago.

Possible Duplicate:

String greater, less, and equal comparison in XmlDocument

Hi开发者_如何转开发, In VBA I have the folowing expression:

 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.

Whath is wrong with the Xpath expression?


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

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.

I guess that MSXML6 no longer provides this obsolete dialect.

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜