Solved

How to handle XML response string

Posted on 2010-11-18
5
3,181 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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…
Suggested Courses

615 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