SOAP'd Web Service reponse parsing with XML

SteveBee

Member
Licensed User
Longtime User
I now have a response from the Web Service I'm accessing via SOAP, using PostString method, as advised by Erel.

However, the response string (/stream) returned is not being parsed properly. I'm guessing this is because there is 'extra' XML in the SOAP response between the first "<?xml..." line and my structured data.

Here's a sample of what I'm getting:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<StoresListingResponse xmlns="http://cheesecake.com.au/">
<StoresListingResult><Stores><Record><StoreName>Albany Creek</StoreName><Address>Shop 19, Albany Market Place,720 Albany Creek Road,Albany Creek QLD 4035</Address><Phone1>07 33254334</Phone1><StoreSysID>89</StoreSysID><Latitude>-27.345486</Latitude><Longitude>152.966995</Longitude></Record><Record><StoreName>Albury</StoreName><Address>Shop 3, 659 Young Street,Albury,NSW 2640</Address><Phone1>02 60232111</Phone1><StoreSysID>117</StoreSysID><Latitude>-36.071899</Latitude><Longitude>146.925766</Longitude></Record><Record><StoreName>Altona</StoreName><Address>114 Millers Road,Altona,VIC
( etc )


I thought about perhaps stripping out all the SOAP: stuff?.... simply enough to Substring or Replace with a string, but the Parser requires a stream.
Can you convert a string back into a stream, after processing?

Or, any other ideas?

TIA
Steve
 

SteveBee

Member
Licensed User
Longtime User
perhaps some progress... seems like a longish way around, but I used the File object to convert adjusted string to stream, thus:

Sub JobDone (Job As String)
Dim s1 As String, s2 As InputStream, p1 As Int, p2 As Int, xmlname As String
If HttpUtils.IsSuccess(WS_url) Then
s1 = HttpUtils.GetString(WS_url)
p1 = s1.IndexOf("<soap:Envelope")
p2 = s1.IndexOf("<soap:Body>")
s1 = s1.SubString2(0, p1) & s1.SubString(p2)
xmlname = "ws_resp.xml"
File.WriteString(File.DirInternalCache, xmlname, s1)
s2 = File.OpenInput(File.DirInternalCache, xmlname)
'parse the xml file
parser.Parse(s2, "Parser")



Getting an error at the Parse line:
"ExpatParser$ParseException: At line 1, column 38: unbound prefix"
(Perhaps my 'adjustment' of the returned string is not what is required)

Inspecting the adjusted string, col 38 is exactly where the first stitch was (var p1)... but the adjusted string looks just like what I was aiming to achieve:

<?xml version="1.0" encoding="utf-8"?><soap:Body><StoresListingResponse xmlns="http://cheesecake.com.au/"><StoresListingResult>&lt;Stores&gt;&lt;Record&gt;&lt;StoreName&gt;Albany Creek&lt;/StoreName&gt;&lt;Address&gt;Shop 19, Albany Market Place,720 Albany Creek Road,Albany Creek QLD


A bit puzzled here, now!

Steve
:sign0104:
 
Upvote 0

SteveBee

Member
Licensed User
Longtime User
I was assuming that items like soap:envelope at the top were screwing the parser's ability to do it's job.... I was not getting correct parsing as found.

I thought I read in another forum thread the parser requires the structured XML to start right after the first ( <?XML.. ) line - did I get that wrong?

I'm having trouble extracting the very long Response string from the debugger, so I can test the XML (see other thread about Log truncation) - how do I get the value of a *long* string from the debugger?

Also , what about my file-based method of converting from string to input stream - is there a better way?
 
Upvote 0
Top