homepage Welcome to WebmasterWorld Guest from 54.227.77.237
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
youtube api in classic asp
musicales




msg:3742846
 4:29 pm on Sep 11, 2008 (gmt 0)

I'm trying to access the description of a youtube video via the api in classic asp (VB script). The description rests in the <media:group> <media:description> node.

I'm a bit of a beginner navigating xml, but I think I need an xpath, and using selectnodes, something like as follows:
objItem.selectNodes("/feed/entry/media:group/media:description") - but I know that's not quite right.

Can anyone give me a pointer as to how to access the description?

I'm posting the xml as it comes through below:

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.example.com/2005/Atom'
xmlnspenSearch='http://example.com/-/spec/opensearchrss/1.0/'
xmlns:gml='http://www.example.com/gml'
xmlns:georss='http://www.example.com/georss'
xmlns:media='http://search.example.com/mrss/'
xmlns:yt='http://gdata.example.com/schemas/2007'
xmlns:gd='http://schemas.example.com/g/2005'>
<id>http://gdata.example.com/feeds/api/standardfeeds/top_rated</id>
<updated>2008-02-21T18:57:10.801Z</updated>
<category scheme='http://schemas.example.com/g/2005#kind'
term='http://gdata.example.com/schemas/2007#video'/>
<title type='text'>Top Rated</title>
<logo>http://www.example.com/img/pic_youtubelogo_123x63.gif</logo>
<link rel='alternate' type='text/html'
href='http://www.example.com/browser?s=tr'/>
<link rel='http://schemas.example.com/g/2005#feed' type='application/atom+xml'
href='http://gdata.example.com/feeds/api/standardfeeds/top_rated'/>
<link rel='self' type='application/atom+xml'
href='http://gdata.example.com/feeds/api/standardfeeds/top_rated?...'/>
<link rel='self' type='application/atom+xml'
href='http://gdata.example.com/feeds/api/standardfeeds/top_rated?...'/>
<author>
<name>YouTube</name>
<uri>http://www.example.com/</uri>
</author>
<generator version='beta'
uri='http://gdata.example.com/'>YouTube data API</generator>
<openSearch:totalResults>99</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<entry>
<id>http://gdata.example.com/feeds/api/videos/ZTUVgYoeN_b</id>
<published>2007-02-16T20:22:57.000Z</published>
<updated>2007-02-16T20:22:57.000Z</updated>
<category scheme="http://schemas.example.com/g/2005#kind"
term="http://gdata.example.com/schemas/2007#video"/>
<category scheme="http://gdata.example.com/schemas/2007/keywords.cat"
term="Steventon"/>
<category scheme="http://gdata.example.com/schemas/2007/keywords.cat"
term="walk"/>
<category scheme="http://gdata.example.com/schemas/2007/keywords.cat"
term="Darcy"/>
<category scheme="http://gdata.example.com/schemas/2007/categories.cat"
term="Entertainment" label="Entertainment"/>
<title type="text">My walk with Mr. Darcy</title>
<content type="html"><div ... html content trimmed ...></content>
<link rel="self" type="application/atom+xml"
href="http://gdata.example.com/feeds/api/videos/ZTUVgYoeN_b"/>
<link rel="alternate" type="text/html"
href="http://www.example.com/watch?v=ZTUVgYoeN_b"/>
<link rel="http://gdata.example.com/schemas/2007#video.responses"
type="application/atom+xml"
href="http://gdata.example.com/feeds/api/videos/ZTUVgYoeN_b/responses"/>
<link rel="http://gdata.example.com/schemas/2007#video.ratings"
type="application/atom+xml"
href="http://gdata.example.com/feeds/api/videos/ZTUVgYoeN_b/ratings"/>
<link rel="http://gdata.example.com/schemas/2007#video.complaints"
type="application/atom+xml"
href="http://gdata.example.com/feeds/api/videos/ZTUVgYoeN_b/complaints"/>
<link rel="http://gdata.example.com/schemas/2007#video.related"
type="application/atom+xml"
href="http://gdata.example.com/feeds/api/videos/ZTUVgYoeN_b/related"/>

<author>
<name>Andy Samplo</name>
<uri>http://gdata.example.com/feeds/api/users/andyland74</uri>
</author>

<media:group>

<media:title type="plain">Shopping for Coats</media:title>
<media:description type="plain">
What could make for more exciting video?
</media:description>
<media:keywords>Shopping, parkas</media:keywords>
<yt:duration seconds="79"/>
<media:category label="People"
scheme="http://gdata.example.com/schemas/2007/categories.cat">People
</media:category>
<media:content
url='http://www.example.com/v/ZTUVgYoeN_b'
type='application/x-shockwave-flash' medium='video'
isDefault='true' expression="full" duration='215' yt:format="5"/>
<media:content
url='rtsp://rtsp2.example.com/ChoLENy73bIAEQ1k30OPEgGDA==/0/0/0/video.3gp'
type='video/3gpp' medium='video'
expression="full" duration='215' yt:format="1"/>
<media:content
url='rtsp://rtsp2.example.com/ChoLENy73bIAEQ1k30OPEgGDA==/0/0/0/video.3gp'
type='video/3gpp' medium='video'
expression="full" duration='215' yt:format="6"/>
<media:player url="http://www.example.com/watch?v=ZTUVgYoeN_b"/>
<media:thumbnail url="http://img.example.com/vi/ZTUVgYoeN_b/2.jpg"
height="97" width="130" time="00:00:03.500"/>
<media:thumbnail url="http://img.example.com/vi/ZTUVgYoeN_b/1.jpg"
height="97" width="130" time="00:00:01.750"/>
<media:thumbnail url="http://img.example.com/vi/ZTUVgYoeN_b/3.jpg"
height="97" width="130" time="00:00:05.250"/>
<media:thumbnail url="http://img.example.com/vi/ZTUVgYoeN_b/0.jpg"
height="240" width="320" time="00:00:03.500"/>
</media:group>

<yt:statistics viewCount="93"/>
<gd:rating min='1' max='5' numRaters='435' average='4.94'/>

<gd:comments>
<gd:feedLink
href="http://gdata.example.com/feeds/api/videos/ZTUVgYoeN_b/comments"
countHint='2197'/>
</gd:comments>

</entry>

[edited by: httpwebwitch at 4:46 pm (utc) on Sep. 11, 2008]
[edit reason] "examplified" all the URLs [/edit]

 

httpwebwitch




msg:3742869
 5:06 pm on Sep 11, 2008 (gmt 0)

I pasted this XML into my XPATH grabber tool, and this is what it prescribes for the node you want:
"/feed/entry/media:group/media:description"

how helpful is that! LOL

Could it be that the XML parser is choking? I think there ought to be a </feed> at the end, after </entry>. Seems like the error is in the XML or in the "objItem.selectNodes" code, not with the XPATH expression. You've got that right.

oh, and assure yourself that "objItem" is the XML's root node, not a child node somewhere down the hierarchy

musicales




msg:3742965
 7:57 pm on Sep 11, 2008 (gmt 0)

great thanks, the step of ensuring it's the root node really helped, together with knowing that was the right xpath- I've solved it now, many thank!

musicales




msg:3742982
 8:18 pm on Sep 11, 2008 (gmt 0)

one more question however - whilst I've now accessed one media:description node, I'm not clear how to specifically target one, when the xml file has about 10 <entry> nodes, each with it's own media:description.
I'm looping through the entries, but when I try to use the number of the loop to access that media:description it doesn't seem to be the correct one. Any pointers?

httpwebwitch




msg:3743424
 12:17 pm on Sep 12, 2008 (gmt 0)

are you using position() [w3schools.com]?

musicales




msg:3743439
 12:36 pm on Sep 12, 2008 (gmt 0)

I've resolved the problem, I was just setting the counter wrong - thanks for the link though, could be useful in future

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved