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

Retrieving XML with Coldfusion

Participant ,
Sep 15, 2009 Sep 15, 2009

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:

http://code.google.com/apis/youtube/2.0/developers_guide_protocol_understanding_video_feeds.html#Und...

How can I edit my code to retrieve the value for this tag?

 <media:thumbnail>
TOPICS
Advanced techniques

Views

883

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 ,
Sep 15, 2009 Sep 15, 2009

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.

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 ,
Sep 15, 2009 Sep 15, 2009

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>

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 ,
Sep 15, 2009 Sep 15, 2009

Copy link to clipboard

Copied

LATEST

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

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