barryk2
asked on
xml/dom/vbscript confused about selectNodes()
Hello,
I want to write a function that initially will print out values of my xml file. I only want to print a certain part of the document so I use a selectNodes() call with some xpath syntax that maybe incorrect. Here is my xml document structure
<profile>
<discovery>
</discovery>
<changes>
<Network_Drives>
<network_drive id_number="0" drive_letter="X:" old_mapping="\\server1\fil es2" new_mapping="\\server2\fil es2" />
<network_drive id_number="1" drive_letter="Y:" old_mapping="\\server2\fil e\test" new_mapping="\\server1\fil e\test"/>
</Network_Drives>
</changes>
</profile>
so I am trying to print out the lines inbetween <Network_Drives> to get something like this:
drive_id 0
drive_letter x:
etc....
The output could be on a single line or spread over multiple lines I just want to access each <network_drive>'s data and be able to store it into a variable eventually. First step would be printing out the data so I know its there.
I do not really even need the descriptions (drive_id, letter) all I want to do is spit out the data (o,x: etc..)
So I have this vbscript going right now
path = "C:\myfile.xml"
Set objXMLDoc = CreateObject("Microsoft.XM LDOM")
objXMLDoc.async = False
objXMLDoc.load(path)
'Set xmlDoc = CreateObject("Msxml2.DOMDo cument.4.0 ")
'xmlDoc.loadXML(path)
WScript.Echo "xml document loaded"
Set NodeList = objXMLDoc.documentElement. selectNode s("//Chang es/Network _Drives")
WScript.Echo "Length " & NodeList.length
For Each Node in NodeList
WScript.Echo Node.Text
Next
My output right now is:
xml document loaded
Length 1
And nothing prints from my loop.....(which I dont understand)
Can anyone help me out with my vbscript code to accomplish my desired output?
Thanks,
Barry
I want to write a function that initially will print out values of my xml file. I only want to print a certain part of the document so I use a selectNodes() call with some xpath syntax that maybe incorrect. Here is my xml document structure
<profile>
<discovery>
</discovery>
<changes>
<Network_Drives>
<network_drive id_number="0" drive_letter="X:" old_mapping="\\server1\fil
<network_drive id_number="1" drive_letter="Y:" old_mapping="\\server2\fil
</Network_Drives>
</changes>
</profile>
so I am trying to print out the lines inbetween <Network_Drives> to get something like this:
drive_id 0
drive_letter x:
etc....
The output could be on a single line or spread over multiple lines I just want to access each <network_drive>'s data and be able to store it into a variable eventually. First step would be printing out the data so I know its there.
I do not really even need the descriptions (drive_id, letter) all I want to do is spit out the data (o,x: etc..)
So I have this vbscript going right now
path = "C:\myfile.xml"
Set objXMLDoc = CreateObject("Microsoft.XM
objXMLDoc.async = False
objXMLDoc.load(path)
'Set xmlDoc = CreateObject("Msxml2.DOMDo
'xmlDoc.loadXML(path)
WScript.Echo "xml document loaded"
Set NodeList = objXMLDoc.documentElement.
WScript.Echo "Length " & NodeList.length
For Each Node in NodeList
WScript.Echo Node.Text
Next
My output right now is:
xml document loaded
Length 1
And nothing prints from my loop.....(which I dont understand)
Can anyone help me out with my vbscript code to accomplish my desired output?
Thanks,
Barry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, I had to change capitalization of "changes" in the XPATH. I don't know if this was due to a typo. I suspect so because your code would have done nothing if it was incorrect. You may need to change it back to a capital to work on your XML file. The sample XML you gace here had a lower case c.