Solved

How to handle XML response string

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Combining Queries 7 54
Append data to an XML file 3 32
DTD and JAVA versions 1 56
Coldfusion builder and IIS 2 39
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

738 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