For example:
Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.validateOnParse = False
objXML.resolveExternals = False
objXML.load("http://www.w3schools.com/dom/books.xml")
'objXML.setProperty "SelectionLanguage", "XPath"
For Each x In objXML.selectNodes("//book[@category='cooking' and @category='children']")
WScript.Echo x.text
Next
For Each y In objXML.selectNodes("//book[position()<3]")
WScript.Echo y.text
Next
When objXML.setProperty "SelectionLanguage", "XPath" is commented then first xpath expression (x object) is returned valid but second xpath expression (y object) raises error:
msxml3.dll (14, 1) : Unknown method.
//book[-->position()<--<3]
If I uncomment objXML.setProperty "SelectionLanguage", "XPath" both expressions work.
My question is when XPath property has to be explicitly set, or what kind of expressions are executed without setting this property?
Default language is not XPath for older versions of MSXML.
You’ve created DomDocument instance using an old, “version independent ProgID”.
Microsoft.XMLDOMcorresponds MSXML 3.0 (if you have) as the last version of MSXML which supported independent ProgIDs.You can determine default selection language like this :
Must be return
XSLPatternwhich a selection language does not supports methods likeposition().XPathis default selection language for MSXML 4.0 and later, so you have two choices using XPath properly.From an ancient article that smells like my teenage times describing the difference between XSL Patterns and XPath.
So, I think you were on minor (!) exceptions.