Copy link to clipboard
Copied
I generally retrieve xml tags like so
<videos>
<video>
<thumbnail_small>
</thumbnail_small>
</video>
</videos>
<cfset temp = QuerySetCell(myquery, "thumbnail_small", #mydoc.videos.video.thumbnail_small.XmlText#, #i#)>
Im trying to do something similar with youtube's api found here, but the xml is slightly different:
How can I edit my code to retrieve the value for this tag?
<media:thumbnail>
Copy link to clipboard
Copied
First option would be to use array notation.
mydoc.videos.video.thumbnail_small.XmlText
Is the same as
mydoc['videos']['video']['thumbnail_small']['XmlText']
This allows for keys that would be illegal in dot notaion such as ['media:thumbnail']
Secondly you may want to learn more about some of the functions that let you work with xml data, such as xmlSearch() and such.
Thirdly you may want to see about using xml stylesheets to dig into the xml data to get it the way you want it.
Copy link to clipboard
Copied
I have
<cfset temp = QuerySetCell(myquery, "thumbnail", mydoc['entry']['media:group']['media:thumbnail']['XmlText'])>
I'm getting nothing returned and no errors
the xml tree is like that
<entry><media:group><media:thumbnail>
...closing tags
my full code is
<cfhttp url="http://gdata.youtube.com/feeds/api/videos/zGAm929CEoE" method="GET" resolveurl="No" ></cfhttp>
<cfset mydoc = XmlParse(CFHTTP.FileContent)>
<cfset myquery = QueryNew("thumbnail")>
<cfset temp = QueryAddRow(myquery, #size#)>
<cfset temp = QuerySetCell(myquery, "thumbnail", mydoc['entry']['media:group']['media:thumbnail']['XmlText'])>
<cfoutput>
#myquery.thumbnail#
</cfoutput>
Copy link to clipboard
Copied
Also be aware of how ColdFusion handles namespaces in XML data. It can be a bit tricky to work with them in CFML.
http://www.google.com/search?q=coldfusion+xml+namespace&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
http://www.aftergeek.com/2006/08/xmlsearch-xpath-and-xml-namespaces-in.html
http://www.talkingtree.com/blog/index.cfm/2005/11/18/XmlSearchNoNameNamespace