Hello everyone,

I have an xml file which I need to loop through using vbscript. The
format looks like the following:

<?xml version="1.0" ?>
<hotfixes>
<Server>
<ServerName>Server1</ServerName>
<hotfix>KB819696</hotfix>
<hotfix>KB823182</hotfix>
<hotfix>KB823353</hotfix>
<hotfix>KB823559</hotfix>
<hotfix>KB824105</hotfix>
</Server>
<Server>
<ServerName>Server2</ServerName>
<hotfix>KB823182</hotfix>
<hotfix>KB823353</hotfix>
<hotfix>KB823559</hotfix>
<hotfix>KB824105</hotfix>
<hotfix>KB824141</hotfix>
</Server>
</hotfixes>

I am very familiar with vbscript but I don't know much in the way of
reading xml files. I am looking for some help to read this file. I
would need to store each servername for each server element, of which
there could be anywhere from 1-300. I also need to loop through the
hotfix nodes for each server element save the hotfix name with the
servername if it matches a certain string. Basically, I need to do the
following:

1. Loop through each server node.
2. Get the server name.
3. Loop through each hotfix element in the current server node and
save the name if it matches some text.
4. Save the servername and any hotfix names found for that server
node.
5. Move onto the next server node and repeat the process until the xml
file is complete.

If anyone could help me out with a script or some code to get me
started, it would be much appreciated.

Re: VBScript Parsing XML Question by Volker

Volker
Mon Jan 29 09:39:36 CST 2007

Jim Gregg schrieb:
> Hello everyone,
>
> I have an xml file which I need to loop through using vbscript. The
> format looks like the following:
>
> <?xml version="1.0" ?>
> <hotfixes>
> <Server>
> <ServerName>Server1</ServerName>
> <hotfix>KB819696</hotfix>
> <hotfix>KB823182</hotfix>
> <hotfix>KB823353</hotfix>
> <hotfix>KB823559</hotfix>
> <hotfix>KB824105</hotfix>
> </Server>
> <Server>
> <ServerName>Server2</ServerName>
> <hotfix>KB823182</hotfix>
> <hotfix>KB823353</hotfix>
> <hotfix>KB823559</hotfix>
> <hotfix>KB824105</hotfix>
> <hotfix>KB824141</hotfix>
> </Server>
> </hotfixes>
>
> I am very familiar with vbscript but I don't know much in the way of
> reading xml files. I am looking for some help to read this file. I
> would need to store each servername for each server element, of which
> there could be anywhere from 1-300. I also need to loop through the
> hotfix nodes for each server element save the hotfix name with the
> servername if it matches a certain string. Basically, I need to do the
> following:
Forget reading the file in VBSCript. It's XML, meaning you can use the
MSXML component.Just start up the component, give it the file to parse and
access the data using xpath or xquery expressions.

Lots of Greetings!
Volker
--
For email replies, please substitute the obvious.

Re: VBScript Parsing XML Question by JHP

JHP
Mon Jan 29 10:11:55 CST 2007

Set objDOM = CreateObject("MSXML2.DOMDocument")
objDOM.Async = False
objDOM.ValidateOnParse = False
objDOM.ResolveExternals = False
objDOM.PreserveWhiteSpace = False

If objDOM.Load("hotfix.xml") Then
Set objNode = objDOM.DocumentElement
Set objNodeList = objNode.SelectNodes("Server")

If objNodeList.Length > 0 Then
For rtnCount = 0 To objNodeList.Length - 1
strText = objNodeList.Item(rtnCount).Text
strSplitText=Split(strText)

For rtnCount2 = 0 To UBound(strSplitText) - 1
WScript.Echo strSplitText(rtnCount2)
Next
Next
End If
Set objNodeList = Nothing
Set objNode = Nothing
End If
Set objDOM = Nothing
WScript.Echo "Completed"


"Jim Gregg" <crazytek@gmail.com> wrote in message
news:1170083645.401214.164880@l53g2000cwa.googlegroups.com...
> Hello everyone,
>
> I have an xml file which I need to loop through using vbscript. The
> format looks like the following:
>
> <?xml version="1.0" ?>
> <hotfixes>
> <Server>
> <ServerName>Server1</ServerName>
> <hotfix>KB819696</hotfix>
> <hotfix>KB823182</hotfix>
> <hotfix>KB823353</hotfix>
> <hotfix>KB823559</hotfix>
> <hotfix>KB824105</hotfix>
> </Server>
> <Server>
> <ServerName>Server2</ServerName>
> <hotfix>KB823182</hotfix>
> <hotfix>KB823353</hotfix>
> <hotfix>KB823559</hotfix>
> <hotfix>KB824105</hotfix>
> <hotfix>KB824141</hotfix>
> </Server>
> </hotfixes>
>
> I am very familiar with vbscript but I don't know much in the way of
> reading xml files. I am looking for some help to read this file. I
> would need to store each servername for each server element, of which
> there could be anywhere from 1-300. I also need to loop through the
> hotfix nodes for each server element save the hotfix name with the
> servername if it matches a certain string. Basically, I need to do the
> following:
>
> 1. Loop through each server node.
> 2. Get the server name.
> 3. Loop through each hotfix element in the current server node and
> save the name if it matches some text.
> 4. Save the servername and any hotfix names found for that server
> node.
> 5. Move onto the next server node and repeat the process until the xml
> file is complete.
>
> If anyone could help me out with a script or some code to get me
> started, it would be much appreciated.
>



Re: VBScript Parsing XML Question by JHP

JHP
Mon Jan 29 10:17:51 CST 2007

You need to remove the - 1 from: UBound(strSplitText) - 1

HTH

"JHP" <goawayspam@GFY.com> wrote in message
news:uDVrr$7QHHA.3444@TK2MSFTNGP03.phx.gbl...
> Set objDOM = CreateObject("MSXML2.DOMDocument")
> objDOM.Async = False
> objDOM.ValidateOnParse = False
> objDOM.ResolveExternals = False
> objDOM.PreserveWhiteSpace = False
>
> If objDOM.Load("hotfix.xml") Then
> Set objNode = objDOM.DocumentElement
> Set objNodeList = objNode.SelectNodes("Server")
>
> If objNodeList.Length > 0 Then
> For rtnCount = 0 To objNodeList.Length - 1
> strText = objNodeList.Item(rtnCount).Text
> strSplitText=Split(strText)
>
> For rtnCount2 = 0 To UBound(strSplitText) - 1
> WScript.Echo strSplitText(rtnCount2)
> Next
> Next
> End If
> Set objNodeList = Nothing
> Set objNode = Nothing
> End If
> Set objDOM = Nothing
> WScript.Echo "Completed"
>
>
> "Jim Gregg" <crazytek@gmail.com> wrote in message
> news:1170083645.401214.164880@l53g2000cwa.googlegroups.com...
>> Hello everyone,
>>
>> I have an xml file which I need to loop through using vbscript. The
>> format looks like the following:
>>
>> <?xml version="1.0" ?>
>> <hotfixes>
>> <Server>
>> <ServerName>Server1</ServerName>
>> <hotfix>KB819696</hotfix>
>> <hotfix>KB823182</hotfix>
>> <hotfix>KB823353</hotfix>
>> <hotfix>KB823559</hotfix>
>> <hotfix>KB824105</hotfix>
>> </Server>
>> <Server>
>> <ServerName>Server2</ServerName>
>> <hotfix>KB823182</hotfix>
>> <hotfix>KB823353</hotfix>
>> <hotfix>KB823559</hotfix>
>> <hotfix>KB824105</hotfix>
>> <hotfix>KB824141</hotfix>
>> </Server>
>> </hotfixes>
>>
>> I am very familiar with vbscript but I don't know much in the way of
>> reading xml files. I am looking for some help to read this file. I
>> would need to store each servername for each server element, of which
>> there could be anywhere from 1-300. I also need to loop through the
>> hotfix nodes for each server element save the hotfix name with the
>> servername if it matches a certain string. Basically, I need to do the
>> following:
>>
>> 1. Loop through each server node.
>> 2. Get the server name.
>> 3. Loop through each hotfix element in the current server node and
>> save the name if it matches some text.
>> 4. Save the servername and any hotfix names found for that server
>> node.
>> 5. Move onto the next server node and repeat the process until the xml
>> file is complete.
>>
>> If anyone could help me out with a script or some code to get me
>> started, it would be much appreciated.
>>
>
>



Re: VBScript Parsing XML Question by Anthony

Anthony
Mon Jan 29 10:37:28 CST 2007


"Jim Gregg" <crazytek@gmail.com> wrote in message
news:1170083645.401214.164880@l53g2000cwa.googlegroups.com...
> Hello everyone,
>
> I have an xml file which I need to loop through using vbscript. The
> format looks like the following:
>
> <?xml version="1.0" ?>
> <hotfixes>
> <Server>
> <ServerName>Server1</ServerName>
> <hotfix>KB819696</hotfix>
> <hotfix>KB823182</hotfix>
> <hotfix>KB823353</hotfix>
> <hotfix>KB823559</hotfix>
> <hotfix>KB824105</hotfix>
> </Server>
> <Server>
> <ServerName>Server2</ServerName>
> <hotfix>KB823182</hotfix>
> <hotfix>KB823353</hotfix>
> <hotfix>KB823559</hotfix>
> <hotfix>KB824105</hotfix>
> <hotfix>KB824141</hotfix>
> </Server>
> </hotfixes>
>
> I am very familiar with vbscript but I don't know much in the way of
> reading xml files. I am looking for some help to read this file. I
> would need to store each servername for each server element, of which
> there could be anywhere from 1-300. I also need to loop through the
> hotfix nodes for each server element save the hotfix name with the
> servername if it matches a certain string. Basically, I need to do the
> following:
>
> 1. Loop through each server node.
> 2. Get the server name.
> 3. Loop through each hotfix element in the current server node and
> save the name if it matches some text.
> 4. Save the servername and any hotfix names found for that server
> node.
> 5. Move onto the next server node and repeat the process until the xml
> file is complete.
>
> If anyone could help me out with a script or some code to get me
> started, it would be much appreciated.
>

Dim oDOM : Set oDOM = CreateObject("MSXML2.DOMDocument.3.0")
oDOM.async = False
oDOM.Load "servers.xml"

Dim oServer, oHotfix
Dim sServer, sHotfix

Const csKB = "KB824105" ' The hotfix name required

For Each oServer In oDOM.selectNodes("/hotfixes/Server")

sServer = oServer.selectSingleNode("serverName").Text
oHotFix = oServer.selectSingleNode("hotfix[. = '" & csKB & "']")

If oHotFix Is Nothing
sHotFix = ""
Else
sHotFix = csKB
End If

RecordServerInfo sServer, sHotFix

Next

Hot fix stuff seems a bit wierd:-

> I also need to loop through the
> hotfix nodes for each server element save the hotfix name with the
> servername if it matches a certain string.

Does 'it' refer to the server or a hotfix?
Are you only interested in one hotfix or many?



Re: VBScript Parsing XML Question by Jim

Jim
Mon Jan 29 11:50:18 CST 2007

Thank you all for the responses. I am trying them out and seeing if I
can make it do what I need. When I was referring to hotfix, what I
meant was that I need to scan each of the <hotfix>KB823182</hotfix>
nodes and if I find one or more that match what I am searching for,
then I would do something with the servername and the hotfix
names...such as write them to a text file.

On Jan 29, 11:37 am, "Anthony Jones" <A...@yadayadayada.com> wrote:
> "Jim Gregg" <crazy...@gmail.com> wrote in messagenews:1170083645.401214.164880@l53g2000cwa.googlegroups.com...
>
>
>
>
>
> > Hello everyone,
>
> > I have an xml file which I need to loop through using vbscript. The
> > format looks like the following:
>
> > <?xml version="1.0" ?>
> > <hotfixes>
> > <Server>
> > <ServerName>Server1</ServerName>
> > <hotfix>KB819696</hotfix>
> > <hotfix>KB823182</hotfix>
> > <hotfix>KB823353</hotfix>
> > <hotfix>KB823559</hotfix>
> > <hotfix>KB824105</hotfix>
> > </Server>
> > <Server>
> > <ServerName>Server2</ServerName>
> > <hotfix>KB823182</hotfix>
> > <hotfix>KB823353</hotfix>
> > <hotfix>KB823559</hotfix>
> > <hotfix>KB824105</hotfix>
> > <hotfix>KB824141</hotfix>
> > </Server>
> > </hotfixes>
>
> > I am very familiar with vbscript but I don't know much in the way of
> > reading xml files. I am looking for some help to read this file. I
> > would need to store each servername for each server element, of which
> > there could be anywhere from 1-300. I also need to loop through the
> > hotfix nodes for each server element save the hotfix name with the
> > servername if it matches a certain string. Basically, I need to do the
> > following:
>
> > 1. Loop through each server node.
> > 2. Get the server name.
> > 3. Loop through each hotfix element in the current server node and
> > save the name if it matches some text.
> > 4. Save the servername and any hotfix names found for that server
> > node.
> > 5. Move onto the next server node and repeat the process until the xml
> > file is complete.
>
> > If anyone could help me out with a script or some code to get me
> > started, it would be much appreciated.Dim oDOM : Set oDOM = CreateObject("MSXML2.DOMDocument.3.0")
> oDOM.async = False
> oDOM.Load "servers.xml"
>
> Dim oServer, oHotfix
> Dim sServer, sHotfix
>
> Const csKB = "KB824105" ' The hotfix name required
>
> For Each oServer In oDOM.selectNodes("/hotfixes/Server")
>
> sServer = oServer.selectSingleNode("serverName").Text
> oHotFix = oServer.selectSingleNode("hotfix[. = '" & csKB & "']")
>
> If oHotFix Is Nothing
> sHotFix = ""
> Else
> sHotFix = csKB
> End If
>
> RecordServerInfo sServer, sHotFix
>
> Next
>
> Hot fix stuff seems a bit wierd:-
>
> > I also need to loop through the
> > hotfix nodes for each server element save the hotfix name with the
> > servername if it matches a certain string.Does 'it' refer to the server or a hotfix?
> Are you only interested in one hotfix or many?- Hide quoted text -- Show quoted text -


Re: VBScript Parsing XML Question by Anthony

Anthony
Mon Jan 29 16:30:36 CST 2007


"Jim Gregg" <crazytek@gmail.com> wrote in message
news:1170093018.496075.227320@h3g2000cwc.googlegroups.com...
> Thank you all for the responses. I am trying them out and seeing if I
> can make it do what I need. When I was referring to hotfix, what I
> meant was that I need to scan each of the <hotfix>KB823182</hotfix>
> nodes and if I find one or more that match what I am searching for,
> then I would do something with the servername and the hotfix
> names...such as write them to a text file.
>


The perhaps you need:-

For Each oServer In oDOM.selectNodes("/hotfixes/Server[hotfix =
'KB823182']")
'Only server nodes that have a hotfix of the specified name will appear
here.
Next