Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

COLDFUSION + XML + Grab Variable from XML Response

Posted on 2005-04-28
6
Medium Priority
?
477 Views
Last Modified: 2013-12-20
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!  
0
Comment
Question by:gr1zwald
  • 4
6 Comments
 
LVL 7

Expert Comment

by:andw928
ID: 13887683
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#
0
 

Author Comment

by:gr1zwald
ID: 13887818
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. "

0
 
LVL 7

Accepted Solution

by:
INSDivision6 earned 2000 total points
ID: 13888524
Maybe just:

<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-1)>
   .  .  .  .  .  .

</cfif>

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:gr1zwald
ID: 13888879
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 !
0
 

Author Comment

by:gr1zwald
ID: 13888961
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>
0
 

Author Comment

by:gr1zwald
ID: 13888968
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>
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
Suggested Courses

572 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