tags:

views:

31

answers:

2

I try to extract specific data from an xml feed that comes from youtube.

XML link: http://gdata.youtube.com/feeds/api/videos/WFPnl8aEPgo?alt=rss

I've been able to extract info like:

Title, Description

using this query string:

Dim Title As String = videoInfoNavigator.SelectSingleNode("/item[1]/title").Value

However, I'm not able to find the proper query string to get info like

media:keywords

A: 

The media:keywords use the media namespace prefix, which is bound to the namespace-uri http://search.yahoo.com/mrss/

If you can register the namespace prefix, you could use an XPATH like this:

/item[1]/media:group/media:keywords

However, if you need a more generic XPATH that does not rely on the namespace prefix, you could express it like this:

/item[1]/*[local-name()='group' and namespace-uri()='http://search.yahoo.com/mrss/']/*[local-name()='keywords' and namespace-uri()='http://search.yahoo.com/mrss/']

Applied to your example code:

Dim Keywords As String = videoInfoNavigator.SelectSingleNode("/item[1]/*[local-name()='group' and namespace-uri()='http://search.yahoo.com/mrss/']/*[local-name()='keywords' and namespace-uri()='http://search.yahoo.com/mrss/']").Value
Mads Hansen
Thanks exemple is working like a charm.I need to study more this exampe as i dont understand the XML much yet :)THAAANKK !
yan
A: 

Try this:

XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("m", "http://search.yahoo.com/mrss/");
var keywords = doc.CreateNavigator().SelectSingleNode("/item/m:group/m:keywords", ns);
Console.WriteLine(keywords.Value);

Note that the prefix you use doesn't matter at all. It's just an abbreviation for the namespace.

John Saunders