Xpath runs on "MSXML2.DOMDocument", but not on "MSXML2.DOMDocument60"

Possible duplicate:
Larger, smaller, and equal string in XmlDocument

Hi, In VBA, I have the following expression:

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

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

What is wrong with the Xpath expression?

+4
source share
1 answer

The expression you provided :

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

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

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

I assume that MSXML6 no longer provides this obsolete dialect.

In your case, you can successfully use this XPath expression :

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

Source: https://habr.com/ru/post/1337980/


All Articles