I have an XML which contain set of 3 Host details.
I want to extract the value of "ipAddress", only for the host whose "AppService" Type is "YesThisIWant" and print it to the console or anything.
I am not intrested in the "ipAddress" of the host whose "AppService" Type is "Useless".
Below is the code i tried, but i dont know how to put check condition. Also the below code is not at all printing Type for the host :( Please help me out.
<CsaPhoneBook xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CsaPhoneBook.xsd"><Version>V1</Version>
<Host>
<name>localhost</name>
<ipAddress>127.0.0.1</ipAddress>
<ip6Address/>
<NetServices/>
<AppServices>
<AppService Type="Useless">
<Collection>
<element>
<name isKey="1">LogicalName</name>
<value>KZWGLDPOUYSQ</value>
</element>
</Collection>
<NetServices>
<NetService>
<Action>open</Action>
<PortNr>108</PortNr>
<Protocol>TCP</Protocol>
</NetService>
</NetServices></AppService>
<AppService Type="Useless">
<Collection>
<element>
<name isKey="1">LogicalName</name>
<value>MVXCEFHKPQZS</value>
</element>
</Collection>
<NetServices><NetService><Action>open</Action><PortNr>104</PortNr><Protocol>TCP</Protocol></NetService></NetServices></AppService>
</AppServices>
<Connection Type="LAN"><LAN/></Connection>
</Host>
<Host>
<name>BLRKMIS0897PC</name>
<ipAddress>172.16.120.29</ipAddress>
<ip6Address/><NetServices/>
<AppServices>
<AppService Type="YesThisIWant">
<Collection>
<element>
<name isKey="1">LogicalName</name>
<value>BLRKMIS0897PC</value>
</element>
</Collection>
</AppService>
</AppServices><Connection Type="LAN"><LAN/></Connection>
</Host>
<Host><name>BLRKMIS1172PC</name><ipAddress>172.16.120.36</ipAddress><ip6Address></ip6Address><NetServices/><AppServices><AppService Type="Useless">
<Collection>
<element>
<name isKey="1">LogicalName</name>
<value>BLRKMIS1172PC</value>
</element>
</Collection>
<NetServices><NetService><Action>open</Action><PortNr>104</PortNr><Protocol>TCP</Protocol></NetService></NetServices></AppService>
</AppServices><Connection Type="LAN"><LAN/></Connection></Host>
</CsaPhoneBook>
And here is the VBScript i tried:
VBScript:
Dim sFSpec : sFSpec = "Some.xml"
Dim sXPathName : sXPath = "/CsaPhoneBook/Host"
Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream (1)
Dim oXDoc : Set oXDoc = CreateObject( "Msxml2.DOMDocument.6.0" )
oXDoc.setProperty "SelectionLanguage", "XPath"
oXDoc.async = False
oXDoc.load sFSpec
For Each Host In oXDoc.SelectNodes("//Host")
For Each AppServices In Host.SelectNodes("./AppServices")
For Each AppService In Host.SelectNodes("./AppService")
Type = AppService.getAttribute("Type")
MsgBox Type
Next
Next
Next