1
votes

I am using cfhttp to call a service call where I am setting the cfhttpparam type = 'url' name $format value = 'xml' to get a response in xml. I have dumped my variable and everything in the filecontent shows that the format is in xml I think since it says and lists all the variables I was calling for. So I assumed using XMLParse for the results would allow me to obtain the data from the results and define them to variables I can use on the web.

<cfset request.getResponse = structNew() />
<cfhttp
method="get"
url="http://testsite"
result="request.getResponse " username="xxxxxx" password="test">
<cfhttpparam type="url" name="$expand" value="GetRoles,GetVendors" />
<cfhttpparam type="url" name="$format" value="xml" />
</cfhttp>
<cfdump var="#request.getResponse #">

<cfset FullResponse = XMLParse(request.getResponse )>

<cf_upXMLToStruct XML="#FullResponse#" SoftError="false" variable = "structResponse">


        <cfset rspFirstName = UCASE(trim(structResponse.XML_STRUCT.FirstName)) />
        <cfset rspShoteName = trim(structResponse.XML_STRUCT.ShortName) />
        <cfset rspCompanyName = trim(structResponse.XML_STRUCT.CompanyName) />

But I am getting an error:

Complex Object types cannot be converted to simple values.

I am still new to XML, so I am not sure what I need to do to evaluate the XML. Here is a snip of the response I receive:

<entry>
<id>http:// TEST/VendorDetailsSet('1000000240')</id>
<title type="text">VendorDetailsSet('1000000240')</title>
<updated>2017-05-18T15:24:44Z</updated>
<category term=" TEST.VendorDetails" 
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="VendorDetailsSet('1000000240')" rel="self" 
title="VendorDetails"/>
<content type="application/xml">
<m:properties>
<d:Address m:type=" TEST.AddressDetails">
<d:HouseNumber/>
<d:Street1/>
<d:Street2/>
<d:City/>
<d:Region/>
<d:PostalCode/>
<d:Country/>
<d:HomePhone/>
<d:MobileNumber/>
<d:FaxNumber/>
<d:CompanyEmail/>
</d:Address>
<d:VendorNumber>1000000240</d:VendorNumber>
<d:VendorName>ABC COMPANY</d:VendorName>
</m:properties>
</content>
</entry>

Do I need to do something to the results before I can XMLParse it or is there another XML tag I can use to evaluate the results?

I am still learning XML in the ColdFusion environment so any assistance or advice to help me learn on how I can grab the data from the XML would be great.

I do also have the option to return the results in JSON format if that makes it easier.

2
Take your code a bit at a time. On which line is it throwing the error?Miguel-F
Agreed. Also, what is the complete error message (usually includes the line of code causing the error)? I am guessing it is the custom tag <cf_upXMLToStruct...>.Leigh
The error is Complex object types cannot be converted to simple values. The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values. The line with the error is <cfset FullResponse = XMLParse(request.getResponse )> I believe I need to evaluate the variable as a structure or do something to the data before I can use XMLParse?user1978340
Hm.. you are positive it is XMLParse? What do you see when you dump the response on the line before that? ie <cfdump var="#request.getResponse #">Leigh
Chart Set utf-8, Error Detail [empty string], Filecontent: <?xml version="1.0" encoding="utf-8"?><entry xml:base="TEST" xmlns="w3.org/2005/Atom" xmlns:m="schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="schemas.microsoft.com/ado/2007/08/… type="text">UserDetailsSet('4440000100')</title><updated>2017-05-19T19:29:13Z</updated><category term="/TEST/UserDetails" scheme="schemas.microsoft.com/ado/2007/08/dataservices/scheme">user1978340

2 Answers

1
votes

I figured out my problem the response was containing multiple components within the response I just needed to change the XMLParse to

<cfset FullResponse = XMLParse(request.getResponse.Filecontent)> 

which Parsed the main XML part. Thanks to everyone that assisted me on this.

0
votes
  1. dump variable to see format

  2. if value is an array, convert to string with arrayToList