xml post as Bytearray

I was working recently on creating a response handler for the flixcloud API.  Fairly standard procedure,

<cfset xmlstr = GetHTTPRequestData().content>
<cfset xmldata = XmlParse(xmlstr)>

Apparently not. It was easy enough to test successfully with my own XML, but running against the actual API yielded this error message every time:

ByteArray objects cannot be converted to strings.

After some investigating, I found the culprit… and, with a simple tostring() around my data, it’s fixed!

<cfset xmlstr = tostring(GetHTTPRequestData().content)>
<cfset xmldata = XmlParse(xmlstr)>

Since we’re talking about working with API’s, another problem I encountered while working with the flixcloud API was syntactically invalid xml names. For examlpe, here in an excerpt from the XML returned:

<job>
<thumbnail-media-file>
   <url>ftp://ftp.MYDOMAIN.com/4F173CA4-3048-7B4D-7B5655ECA9D97CCC.png/tn_</url>
   <total-size>41817</total-size>
   <number_of_thumbnails>1</number_of_thumbnails>
   <cost>9</cost>
 </thumbnail-media-file>
</job>

If you parse this into a coldfusion variable called “xmldata”, you’d think you could get to the “total-size” xml text in this way:

<cfoutput>#xmldata.job.thumbnail-media-file.total-size.xmltext#</cfoutput>

However, you would be wrong. Coldfusion does not like those dashes. Here’s how to call it correctly:

<cfoutput>#xmldata.job["thumbnail-media-file"]["total-size"].xmltext#</cfoutput>

and if you thought you should double quote to escape any database issues, it doesn’t seem to work. just leaving the single quotes worked fine.

Tags: , ,

Leave a Reply

Spam protection by WP Captcha-Free