XMLDOM - how to display SelectNodes output?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DaveF
Posts: 24
Joined: 14 Nov 2016, 17:01

XMLDOM - how to display SelectNodes output?

09 Nov 2021, 16:29

Hi
This may not be a direct AHK problem, but I hope someone can spot the error/solution for me.

I load Stations_New.xml, & manipulate it using selectNodes & selectsinglenode.
I'm trying to use the .xml property to display the results.

msgbox % doc.xml displays the xml file as expected.

msgbox % No_CRS.xml returns an 'Unknown Name' error

msgbox % No_CRS.length returns a number of the expected total number of nodes, proving there's some data in there.

msgbox % SingleNo_CRS.xml returns the first node, as expected.

If .xml isn't a property of selectNodes, how do I store/display it's results?

Code: Select all

FileRead, xmldata, Stations_New.xml
doc := ComObjCreate("MSXML2.DOMDocument.6.0")
doc.setProperty("SelectionLanguage", "XPath")
doc.async := false
doc.loadXML(xmldata)
		
No_CRS := doc.selectNodes("osm/node[tag[@k='railway'][@v='station']]")
SingleNo_CRS := doc.selectsinglenode("osm/node[tag[@k='railway'][@v='station']]")

msgbox % doc.xml
msgbox % No_CRS.xml
msgbox % No_CRS.length
msgbox % SingleNo_CRS.xml
nadure
Posts: 22
Joined: 26 Mar 2021, 23:02
Location: Korea
Contact:

Re: XMLDOM - how to display SelectNodes output?

12 Nov 2021, 03:49

this occurs because of namespace in xml.

in docs.
https://docs.microsoft.com/en-us/previous-versions/troubleshoot/msxml/msxml-6-matching-nodes-not-return

for example, at my post. i used namespace.

viewtopic.php?style=2&t=95251&p=423433

but the problem is that can't find selectNodes results when no namespace header.

but if add this, it works.

Code: Select all

nameSpace := format("{1}main='{2}' {1}x14ac='{3}' {1}r='{4}' {1}mc='{5}'"
                , x
                , this.mainNs
                , this.x14acns
                , this.rns
                , this.mcns)
                
sheetDoc := this.LoadXML(this.sheetXML)
sheetDoc.setProperty("SelectionLanguage", "XPath")
sheetDoc.setProperty("SelectionNamespaces" , sheetXMLNameSpace)
        
in this code, key is main(i 'd added it.)

Code: Select all

selectSingleNode("//main:somenode/")
it works.
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: XMLDOM - how to display SelectNodes output?

12 Nov 2021, 05:19

doc.selectNodes() returns an IXMLDOMNodeList.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder, Tech Stuff and 362 guests