• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Submit values and retrieve responses from xml api

Participant ,
Jan 12, 2010 Jan 12, 2010

Copy link to clipboard

Copied

I use this code to submit to an api

<cfhttp url="<api url>" method="GET" resolveurl="No" ></cfhttp>

I get back


<VerifySignatureResponse>
−<VerifySignatureResult>
<VerificationStatus>Success</VerificationStatus>
</VerifySignatureResult>
</VerifySignatureResponse>

How do I retrieve the response? I ned to get back the Success for the VerificationStatus parameter

TOPICS
Advanced techniques

Views

680

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 12, 2010 Jan 12, 2010

Copy link to clipboard

Copied

If the response is xml, try parsing it with XMLParse(). It returns a "structure-like" object. You can then access the elements with dot/array notation. Cfdump the results of XMLParse() to visualize how to access the element you need.

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_t-z_23.html

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_t-z_23.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2010 Jan 13, 2010

Copy link to clipboard

Copied

<!--- general case --->


<!--- <cfxml variable="xmlString"><cfoutput>#cfhttp.FileContent#</cfoutput></cfxml> --->

<cfxml variable="xmlString">
<VerifySignatureResponse>
<VerifySignatureResult>
<VerificationStatus>Success</VerificationStatus>
</VerifySignatureResult>
</VerifySignatureResponse>
</cfxml>

<cfset statusArray=xmlSearch(xmlString,"//VerificationStatus")>
<cfdump var="#statusArray#">
status: <cfoutput>#statusArray[1].xmlText#</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 13, 2010 Jan 13, 2010

Copy link to clipboard

Copied

I don't really understand this cfxml code

In this case you hard coded the word Success.

In the real application the xml is hosted on another server. I send some variables in the URL querystring to the url.

When I enter the url directly in the address bar o the browser I see the xml sheet and the response.

I want to automatically read what was returned through coldfusion

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 13, 2010 Jan 13, 2010

Copy link to clipboard

Copied

He was showing you and example of how to parse and view XML data.  Since he did not have access to your web service to get the xml he created an example of it in his code so that he had some xml data to parse and show you.

You can assume everthing in between the <cfxml...> tags is the same as your <cfhttp...> tag.  It creates some xml data to be utilized.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 13, 2010 Jan 13, 2010

Copy link to clipboard

Copied

Thanks I used some working code I had on another page and rebuild around this app.

I always need to have these resources next to me because I forget how to build the code

this works for me

<cfhttp url="<api url>" method="GET" resolveurl="No" ></cfhttp>

<cfset mydoc = XmlParse(CFHTTP.FileContent)>
<cfset pb = mydoc.variable1.XmlChildren>
<cfset size = ArrayLen(pb)>
<cfset myquery = QueryNew("variable1,variable2, variable3")>
<cfset temp = QueryAddRow(myquery, #size#)>
<cfset temp = QuerySetCell(myquery, "variable3", #mydoc.variable3.XmlText#)>

<cfif #mydoc.variable1.variable2.variable3.XmlText# eq "Success">

Action
</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2010 Jan 13, 2010

Copy link to clipboard

Copied

LATEST

this works for me

<cfhttp url="<api url>" method="GET" resolveurl="No" ></cfhttp>

<cfset mydoc = XmlParse(CFHTTP.FileContent)>
<cfset pb = mydoc.variable1.XmlChildren>
<cfset size = ArrayLen(pb)>
<cfset myquery = QueryNew("variable1,variable2, variable3")>
<cfset temp = QueryAddRow(myquery, #size#)>
<cfset temp = QuerySetCell(myquery, "variable3", #mydoc.variable3.XmlText#)>

<cfif #mydoc.variable1.variable2.variable3.XmlText# eq "Success">

Action
</cfif>


You apparently didn't take the hint, Ian's or mine. What you've done may be correct, it unnecessarily involves too many functions. You could really do it more efficiently, like this

<cfxml variable="xmlString"><cfoutput>#cfhttp.FileContent#</cfoutput></cfxml>

<cfset statusArray=xmlSearch(xmlString,"//VerificationStatus")>

<cfif statusArray[1].xmlText eq "Success">
Action
</cfif>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation