Topic Options
#56157 - 07/27/18 11:41 AM VBScript XML Get Values
Tom Rymes Offline
OL Toddler

Registered: 02/11/08
Posts: 43
Loc: NH, USA
I am using a VBScript to interact with a SOAP Web Service, as the SOAP Client cannot do what I need. I then need to parse values from the response, which is XML. I had been saving the response as a variable, using the "Create File" action to create a new file whose contents were the response, and then "Set Job Info and Variables", to read this information, but it is quite slow. I thought I could save the trip out to the filesystem and speed things up by having the VBScript load the XML directly and parse the response directly. However, I am having trouble finding a combination that works in PP Watch.

I found this topic that got me started, but I need to figure out how to actually select a specific node and view its value. Of course, the XML is fairly complex, so that isn't making it easier.

So far, I have managed to load the result into an XMLDOM object with this bit of code:

Code:
dim xmlString
dim objXMLDoc
dim NodeList

'Replace " with '
xmlString = Replace(Watch.GetVariable("DSCustomerFields"),chr(34),chr(39))

'Create object and load XML
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.loadXML(xmlString)


Now need to replicate the what I can achieve with "Set Job Info and Variables" using this string "xmlget('/soap:Envelope[1]/soap:Body[1]/AddCustMasterResponse[1]/p_lAccountNum[1]',Value,KeepCase,NoTrim)"

I think it's pretty simple, but I am struggling to figure out the right combination of instructions, and it's taking forever to figure this out by trial and error.


Edited by Tom Rymes (07/27/18 11:43 AM)
Edit Reason: clarified text

Top
#56158 - 07/27/18 01:05 PM Re: VBScript XML Get Values [Re: Tom Rymes]
Tom Rymes Offline
OL Toddler

Registered: 02/11/08
Posts: 43
Loc: NH, USA
I may have answered my own question, but while this works, it sure doesn't seem elegant, or the most efficient answer. I'd appreciate anyone's thoughts on how to improve this:

Code:
dim xmlString
dim objXMLDoc
dim NodeList

xmlString = Replace(Watch.GetVariable("DSCustomerFields"),chr(34),chr(39))

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.loadXML(xmlString)

Set NodeList = objXMLDoc.documentElement.selectNodes("/soap:Envelope/soap:Body/AddCustMasterResponse/p_lAccountNum")

For Each Node In NodeList
   Watch.SetVariable("acct"),Node.text
   Watch.Log "Set Variable 'acct' to :" & Watch.GetVariable("acct"), 1
Next

Set NodeList = objXMLDoc.documentElement.selectNodes("/soap:Envelope/soap:Body/AddCustMasterResponse/p_lErrorCode")

For Each Node In NodeList
   Watch.SetVariable("SOAPError"),Node.text
   Watch.Log "Set Variable 'SOAPError' to :" & Watch.GetVariable("SOAPError"), 1
Next

Set NodeList = objXMLDoc.documentElement.selectNodes("/soap:Envelope/soap:Body/soap:Fault")

For Each Node In NodeList
   Watch.SetVariable("SOAPFault"),Node.text
   Watch.Log "Set Variable 'SOAPFault' to :" & Watch.GetVariable("SOAPFault"), 1
Next

Top
#56163 - 07/30/18 08:10 AM Re: VBScript XML Get Values [Re: Tom Rymes]
Philippe F. Online   content
OL Expert

Registered: 09/06/00
Posts: 1929
Loc: Objectif Lune, Montreal, Qc
Hard to say without having your XML file at hand, but the following should work. It uses the selectSingleNode method instead of selectNodes:
Code:
dim xmlString
dim objXMLDoc
dim NodeList

xmlString = Replace(Watch.GetVariable("DSCustomerFields"),chr(34),chr(39))

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.loadXML(xmlString)

set Node = objXMLDoc.documentElement.selectSingleNode("/soap:Envelope/soap:Body/AddCustMasterResponse/p_lAccountNum")
Watch.SetVariable("acct"),Node.text
Watch.Log "Set Variable 'acct' to :" & Watch.GetVariable("acct"), 1

set Node = objXMLDoc.documentElement.selectSingleNode("/soap:Envelope/soap:Body/AddCustMasterResponse/p_lErrorCode")
Watch.SetVariable("SOAPError"),Node.text
Watch.Log "Set Variable 'SOAPError' to :" & Watch.GetVariable("SOAPError"), 1

set Node = objXMLDoc.documentElement.selectSingleNode("/soap:Envelope/soap:Body/soap:Fault")
Watch.SetVariable("SOAPFault"),Node.text
Watch.Log "Set Variable 'SOAPFault' to :" & Watch.GetVariable("SOAPFault"), 1
_________________________
Technical Product Manager
I don't want to achieve immortality through my work; I want to achieve immortality through not dying - Woody Allen

Top