Question : How to parse xml node into variables using vb script

Need to read xml nodes into variables. xml data will be all on one line -- but this is what i have from another script I am using in a similar way...

I imagine I will need to identify each node, or maybe assign each variable a start and end tag and read the information in between them. Not sure, though... that's why I created this.

Any thoughts?

Jason
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Dim eMailData
'eMailData = Split(Watch.GetJobInfo(7),",") 'this is from the other process
eMailData = 'this is where i need help

strType = eMailData(0)
strMailTo = eMailData(1)
strMailCc = eMailData(2)
strMailBcc = eMailData(3)
strMailSubject = eMailData(4)
strMailBody = eMailData(5)
strMailFrom = eMailData(6)

Watch.SetJobInfo 1, strMailTo
Watch.SetJobInfo 2, strMailCc
Watch.SetJobInfo 3, strMailBcc
Watch.SetJobInfo 4, strMailSubject
Watch.SetJobInfo 5, strMailBody
Watch.SetJobInfo 6, strMailFrom

Answer : How to parse xml node into variables using vb script

Well, the following will certainly work, what do you think of this approach?

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
strXmlData = "<MailForm> <MailFrom>[email protected]</MailFrom> <MailTo>[email protected]; [email protected]</MailTo> <MailCc>email;email</MailCc> <MailBcc>email;email</MailBcc> <MailSubject>Subject workds</MailSubject> <MailBody>kdkfj dkfj d,d fkjdkjl,, djfkjd,,, akjkjfkjdk kdfkdjfkd,df jkdjkjdfkjaldfj a</MailBody> </MailForm>"
 
' Load XML data
set objXML = CreateObject("Microsoft.XMLDOM")
objXML.Async = "False"
objXML.LoadXML(strXmlData)
 
' Loop through all nodes and display their values
For Each objNode in objXML.DocumentElement.ChildNodes
  Wscript.Echo objNode.Nodename & " = " & objNode.Text
Next
 
' Access nodes by name, and assign to variables
strMailFrom = objXML.GetElementsByTagName("MailFrom").Item(0).Text
strMailTo = objXML.GetElementsByTagName("MailTo").Item(0).Text
strMailCc = objXML.GetElementsByTagName("MailCc").Item(0).Text
strMailBcc = objXML.GetElementsByTagName("MailBcc").Item(0).Text
strMailSubject = objXML.GetElementsByTagName("MailSubject").Item(0).Text
strMailBody = objXML.GetElementsByTagName("MailBody").Item(0).Text
 
' Display variable values
Wscript.Echo "strMailFrom= " & strMailFrom   
Wscript.Echo "strMailTo= " & strMailTo     
Wscript.Echo "strMailCc= " & strMailCc     
Wscript.Echo "strMailBcc= " & strMailBcc    
Wscript.Echo "strMailSubject= " & strMailSubject
Wscript.Echo "strMailBody= " & strMailBody
Random Solutions  
 
programming4us programming4us