Solved

How to handle XML response string

Posted on 2010-11-18
5
3,023 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
  • 3
5 Comments
 
LVL 83

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 500 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

808 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