Discussion:
VBScript and XML Parser
(too old to reply)
Thomas Bosscher
2004-05-11 18:50:43 UTC
Permalink
Does anyone have an example of how to retrieve data from an XML file using
VBScript?

I would like to map a set of network drives in which the data fro the drive
mappings are located in an xml file like the one below:

<MapDrives>
<DriveMapping name="NetworkShare">
<Description>Network Share</Description>
<Drive>K:</Drive>
<Share>\\SERVER\Share\</Share>
<Group>Group_All</Group>
</DriveMapping>
<DriveMapping name="AppsShare">
<Description>Network Share</Description>
<Drive>L:</Drive>
<Share>\\Server\Apps\</Share>
<Group>Group_All</Group>
</DriveMapping>
</MapDrives>

Thanks for any direction in advance. I have been searching for an example
online with no luck.

Tom
Operations
2004-05-13 07:31:07 UTC
Permalink
Hi Thomas!

Using DOM via MSXML, the critical functions you need are SelectNodes and SelectSingleNode. Both allow you to apply programatically XPath expressions to retrieve whatever you want, like this:

Dim oXML, somevariable, oNode, cNodes

Set oXML = CreateObject("MSXML4.DomDocument40")
oXML.load(filepath)

' This simple example gets a Node collection with all "Drive" nodes anywhere in the xml hierarchy
' and then puts each node textual value to a variable
Set cNodes = oXML.documentElement.SelectNodes("//DRIVE")
For Each oNode In cNodes
somevariable = oNode.text
Next
Set cNodes = Nothing

' This simple example gets the first "Share" node, in source order, and saves its textual value to a variable
somevariable = oXML.documentElement.SelectSingleNode("//SHARE[1]").text

Set oXML = Nothing

The tricky part is the Xpath thing. As you can see, the rest is a done deal.

----- Thomas Bosscher wrote: -----

Does anyone have an example of how to retrieve data from an XML file using
VBScript?

I would like to map a set of network drives in which the data fro the drive
mappings are located in an xml file like the one below:

<MapDrives><DriveMapping name="NetworkShare"><Description>Network Share</Description><Drive>K:</Drive><Share>\\SERVER\Share\</Share><Group>Group_All</Group></DriveMapping><DriveMapping name="AppsShare"><Description>Network Share</Description><Drive>L:</Drive><Share>\\Server\Apps\</Share><Group>Group_All</Group></DriveMapping></MapDrives>

Thanks for any direction in advance. I have been searching for an example
online with no luck.

Tom

Continue reading on narkive:
Loading...