Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to handle XML response string

Posted on 2010-11-18
5
Medium Priority
?
3,266 Views
Last Modified: 2013-11-18
OK - I've stared at this too long.  I've been around CF forever, but just now getting into a new territory with an XML project.
I don't have control over the returned format of a request.  Here is an example of what is being returned as the XML Reply from a web service:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:ob002p2_XMLResponse xmlns:ns="http://ob002.wsbeans.iseries/xsd">
<ns:return>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;ob002&gt;
  &lt;ARPRDNO&gt;10889&lt;/ARPRDNO&gt;
  &lt;ARPRDNO&gt;10548&lt;/ARPRDNO&gt;
  &lt;ARPRDNO&gt;131000&lt;/ARPRDNO&gt;
  &lt;ARACTSP&gt;32.50&lt;/ARACTSP&gt;
  &lt;ARACTSP&gt;19.00&lt;/ARACTSP&gt;
  &lt;ARACTSP&gt;16.75&lt;/ARACTSP&gt;
  &lt;ARSRCREF&gt;DSC DISCONTINUED&lt;/ARSRCREF&gt;
  &lt;ARSRCREF&gt;SOME MESSAGE&lt;/ARSRCREF&gt;
  &lt;ARSRCREF&gt;ANOTHER MESSAGE&lt;/ARSRCREF&gt;
&lt;/OB0017P2&gt;
</ns:return>
</ns:ob0017p2_XMLResponse>
</soapenv:Body>
</soapenv:Envelope>

Open in new window

It's like an XML document that is a value within another XML document!

I'm looking for suggestions on how to get this data from the embedded document in a way that makes sense rather than having to manipulate the string before I parse it.
I've tried XMLSearch pointing at //return, however that doesn't return anything - I'm sure I am just missing something.
 
I know that once I can get at the string (XML Doc) that is buried inside, I'll be able to manage the data.  I'm just at a loss as to how to get to it!

Thanks in advance...
0
Comment
Question by:C4S-DT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 34169585
The code you're looking at is called SOAP, (Simple Objects Access Protocol).  I don't know ColdFusion but there are a lot of links about ColdFusion and SOAP.  I suggest a search for 'coldfusion soap tutorial'.  A lot of the links I saw were for generating the SOAP file, not reading it, so you may have to wade thru some things to find what you need.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 34169745
>> I've tried XMLSearch pointing at //return, however that doesn't return anything

Why not just access the node directly?

  <cfset doc = xmlParse(xml)>
  <cfset result = doc.Envelope.body.ob002p2_XMLResponse.return>

>> <ns:return>

To use xmlsearch, you have account for the namespace (ie "ns").  I'd look for
something more elegant,  but this works in CF9
<cfset result = xmlSearch(xmldoc, "//*[local-name()='return']")>

This *might* work for CF8. It didn't work for me w/CF9
http://www.aftergeek.com/2006/08/xmlsearch-xpath-and-xml-namespaces-in.html
<cfset result = XMLSearch(xmldoc, "//*:return")>

0
 
LVL 52

Expert Comment

by:_agx_
ID: 34169949
>> <cfset doc = xmlParse(xml)>
Ignore the XMLParse().  It's just testing code ..
0
 
LVL 2

Author Closing Comment

by:C4S-DT
ID: 34170162
Thanks aqx.  Been in the CF world since the beginning. Can't believe I'm just now digging into a ton of XML all at once.
Well covered answer that is much appreciated!
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34170619
You're welcome :)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question