Search XML Files
In a VB Script I am writing I needed to read an XML file and read a GUID from it.
The XML file looks like this (there’s more data in it, I am just displaying a small piece so you can see the structure):
7af322bd-9c0c-4edb-a55d-97f4b240abf2
DesktopSiloEven
fa341079-5376-4baa-8898-1048421506df
12a072bb-9338-418a-9be1-e0e9c8ed2780
77d73762-745d-49f3-8cb3-6b7fedaf70a2
3f5b59a9-1989-43b7-9354-871841aa65a8
37bdf4a7-1ca6-a7eb-0d4e-ec3e964c73bd
550f45d9-4b22-430d-b972-06671f4da7cb
DesktopSiloUneven
fa341079-5376-4baa-8898-1048421506df
12a072bb-9338-418a-9be1-e0e9c8ed2780
bf263ad1-3c89-4503-a82f-81e1dc909efb
3f5b59a9-1989-43b7-9354-871841aa65a8
37bdf4a7-1ca6-a7eb-0d4e-ec3e964c73bd
I needed to lookup the value of the GUID Node of the NodeGroup with a specific name. We could do this with a classic for loop, enumerating all nodes, enumerate it’s children etc.
But there’s a much simpler way using a search filter:
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load("dnkemss.xml")
GuidEven = xmlDoc.selectSingleNode"/dsDASe/NodeGroup[Name='DesktopSiloEven']/GUID").text
GuidOdd = xmlDoc.selectSingleNode("/dsDASe/NodeGroup[Name='DesktopSiloUneven']/GUID").text
Remko Weijnen
Was once an enthusiastic PepperByte employee but is now working elsewhere. His blogs are still valuable to us and we hope to you too.