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

How to read XMLParse(cfhttp.FileContent) - HELP!!!!

Guest
Aug 19, 2009 Aug 19, 2009

Copy link to clipboard

Copied

Hi,

I have just managed to sort out how to connect to a .net web service a pass it login details using SOAP headers.  What I need to figure out now (and can't) is how to get the values of the 2 vars it has sent back (AuthenticateUserResponse & token).  Here is the page with a dump of the #localscope.soapresponse# (best viewed in Firefox) for some reason:

http://www.prevu.tv/xxxtest2.cfm

Can some one please tell me how I can access the returned data please?  Example code woul dbe extremely helpfull.

Thanks.

TOPICS
Advanced techniques

Views

3.3K

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

correct answers 1 Correct answer

Advisor , Aug 20, 2009 Aug 20, 2009

Take a look at the sample below.  As noted by Skinner you'll need to account for namespaces when using XmlSearch.  See: http://www.aftergeek.com/2006/08/xmlsearch-xpath-and-xml-namespaces-in.html

results.authenticateUserResultValue and results.tokenValue should have the values you're looking for.

<!--- soap sample data, in you case soapInfo would be the contents of cfhttp.FileContent --->
<cfsavecontent  variable="soapInfo"><?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://sch

...

Votes

Translate

Translate
Advisor ,
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

You'll want to investigate Xpath for querying your XML documents.

Take a look at "Extracting data with XPath" in the CF documentation.
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=XML_16.html#1140176

Microsoft has a reference guide for Xpath
http://msdn.microsoft.com/en-us/library/ms256471.aspx

The XML chapters for the book "ColdFusion 8 Web Application Construction Kit Volume 2: Application Development" are available for download on the author's website.
http://www.forta.com/books/0321515463/

If you post the XML text you are trying to parse I might be able to provide a sample.

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
Guest
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

Hi Bob,

I really am lost/stuck on this.

Here is the response I get from the soap header response after parsing the cfhttp.FileContent to localscope.soapresponse i.e. <cfset localscope.soapresponse = XMLParse(cfhttp.FileContent) />.

When I output the value of # #localscope.soapresponse# AND dump the results <cfdump var="#localscope.soapresponse#"> this is what I get (only seems to work in Firefox):

http://www.prevu.tv/xxxTest2.cfm

You will see at the top of the page are the results "OK" (or the AuthenticateUserResult) and then a key value (or the token).  What for the life of me I cannot seem to do is to be able to access/reference these values as separate vars that I can use in other code.  I have tried stuff like:

#["soap:Envelope"].["soap:Body"].AuthenticateUserResponse.AuthenticateUserResult.XmlText#

But that does not seem to work either.  Can you please provide me some sample code of how to solve this problem?

Thanks a million,

Aaron

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
Advisor ,
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

Calling XmlParse converts the text in cfhttp.FileContent to an object representation of an XML document. Can you post the contents of cfhttp.FileContent (without the XmlParse)?

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
Guest
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

If I don't use XMLParse and just go <cfoutput>#cfhttp.FileContent#</cfoutput> I get the following output to screen:

OKe1ad3dc8-9b47-48d0-a2cc-46670a031674

Above are the two results I am trying to access - the response "OK" and the token value "e1ad3dc8-9b47-48d0-a2cc-46670a031674".

If I view the source code for the page I get this:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AuthenticateUserResponse xmlns="http://services.iceportal.com/service"><AuthenticateUserResult>OK</AuthenticateUserResult><token>e1a...>

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
Guest
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

Or...take a look at the actual page:

http://www.prevu.tv/xxxTest3.cfm

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 ,
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

ColdFusion does not make using XML data the utilizes name spaces as easy as it could be.  I don't have the information at my fingertips, but I know that I have Google searched ColdFusion, XML and NameSpace and found some very helpful blogs and resources that explain exacty how you properly dig into the xml structure when name spaces are involved.

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
Advisor ,
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

LATEST

Take a look at the sample below.  As noted by Skinner you'll need to account for namespaces when using XmlSearch.  See: http://www.aftergeek.com/2006/08/xmlsearch-xpath-and-xml-namespaces-in.html

results.authenticateUserResultValue and results.tokenValue should have the values you're looking for.

<!--- soap sample data, in you case soapInfo would be the contents of cfhttp.FileContent --->
<cfsavecontent  variable="soapInfo"><?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AuthenticateUserResponse xmlns="http://services.iceportal.com/service"><AuthenticateUserResult>OK</AuthenticateUserResult><token>e6384ea8-48fe-4ab3-934d-4274446008c5</token></AuthenticateUserResponse></soap:Body></soap:Envelope></cfsavecontent>

<!--- verify soapInfo is an xml document --->
<cfif IsXml(soapInfo)>

    <cfset results=StructNew() />

    <cfset soapXmlObj=XmlParse(soapInfo) /> <!--- convert xml document text to CF XML object --->

    <!--- should get an array with one item --->
    <cfset results.authenticateUserResultArray=XmlSearch(soapXmlObj, "//*[local-name()='AuthenticateUserResult']" ) />
   
    <!--- should get an array with one item --->
    <cfset results.tokenArray=XmlSearch(soapXmlObj, "//*[local-name()='token']") />

    <!--- extract XmlText from array items, this will fail if arrays are empty, you may want to validate the contents of  results.authenticateUserResultArray and results.authenticateUserResultArray to verify items were found --->
    <cfset results.authenticateUserResultValue=results.authenticateUserResultArray[1].XmlText />
    <cfset results.tokenValue=results.authenticateUserResultArray[1].XmlText />

    <cfdump var="#results#" />

<cfelse>
    NOT VALID XML!
</cfif>

Note that the forum may break up the xml text inside the cfsavecontent tags.  This may cause problems when using this sample

Message was edited by: JR "Bob" Dobbs Added comment about forum breaking up xml text.

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