Solved

How to handle XML response string

Posted on 2010-11-18
5
2,885 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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
>> 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_
Comment Utility
>> <cfset doc = xmlParse(xml)>
Ignore the XMLParse().  It's just testing code ..
0
 
LVL 2

Author Closing Comment

by:C4S-DT
Comment Utility
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_
Comment Utility
You're welcome :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now