Link to home
Start Free TrialLog in
Avatar of gr1zwald
gr1zwald

asked on

COLDFUSION + XML + Grab Variable from XML Response

i send and XML request to a service ... and it returns the following XML Response:

<?xml version="1.0" encoding="Cp1252"?>
<ARCXML version="1.1">
<RESPONSE>
<LAYOUT>
<ENVELOPE minx="0" miny="0" maxx="8" maxy="8" />
<OUTPUT url="http://servername/output/WP1_ORCA562846923.jpg" width="2400" height="2400"/>
</LAYOUT>
</RESPONSE>
</ARCXML>

what is the proper way to grab the URL in the output... (ie. <OUTPUT url="http://servername/output/WP1_ORCA562846923.jpg" width="2400" height="2400"/>

all i am interested in is getting the URL conained in the response and assigning it to a variable i can use in my CF application.

i assumed i could do something like this ...

<cfset parse = XMLParse(cfhttp.filecontent)>
#parse.response.layout.output.XmlAttributes.url#

but this returns an error, im sure this is something really simple.

any help is greatly appreciated!  
Avatar of andw928
andw928

Well, first off you don't have a closing tag for envelope and output, so I'm not sure what is up, but this might work:

<cfset parse = XMLParse(cfhttp.filecontent)>
#parse.response.layout[1].output[1].XmlAttributes.url#
Avatar of gr1zwald

ASKER

thanks,

as for the no closing tag for envelope and output ... that is the way that it is returned from the service ... so im not sure what is going on there ...

your suggestion returns the same error i have been getting ...

"Element RESPONSE.LAYOUT is undefined in PARSE. "

ASKER CERTIFIED SOLUTION
Avatar of INSDivision6
INSDivision6

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sweet !  it kinda worked ... lol

when i used the code pasted above it came back with an error ... saying ...

"Parameter validation error for function MID.  
The function takes 3 parameters."

So just for fun i removed the 'end-start-1' in the following line
   <cfset myURL=Mid(out, start, Len(out), end-start-1)>

this did return the URL .. but with some extra stuff behind it .. (like the image size and etc ..) .. i assume it did that because i removed the part where u tell it to terminate ...

but we are verrry close .. do u know how to write this without causing the error .. ??

i really appreciate this !
w00t i got it ... i removed .. Len(out) and it all seems to be working fine !


<cfset out=cfhttp.filecontent>
<cfset str='<OUTPUT url="'>
<cfset start=FindNoCase(str, out)>
<cfif start EQ 0>
   Wrong format
<cfelse>
   <cfset start=start+Len(str)>
   <cfset end=FindNoCase('"', out, start)>
   <cfset myURL=Mid(out, start, end-start-1)>
   .  .  .  .  .  .

</cfif>
err .. and i removed the '-1' from start

<cfset out=cfhttp.filecontent>
<cfset str='<OUTPUT url="'>
<cfset start=FindNoCase(str, out)>
<cfif start EQ 0>
   Wrong format
<cfelse>
   <cfset start=start+Len(str)>
   <cfset end=FindNoCase('"', out, start)>
   <cfset myURL=Mid(out, start, Len(out), end-start)>
   .  .  .  .  .  .

</cfif>