0

I have the xml file below from a blogger rss feed

<rss> <channel>
 <item>
         <guid isPermaLink="false">tag:blogger.com,1999:blog-000000.post-0000000</guid>
         <pubDate>Wed, 25 May 2016 18:00:00 +0000</pubDate>
         <atom:updated>2016-05-25T19:01:58.172+01:00</atom:updated>
         <category domain="http://www.blogger.com/atom/ns#"></category>
         <category domain="http://www.blogger.com/atom/ns#"></category>
         <title> "sorry... google play services has stopped"  </title>
         <description>bla bla bla bla </description>
         <link>http://0000.blogspot.com/2016/05/sorry-google-play-services-has-stopped.html</link>
         <author>noreply@blogger.com </author>
         <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://2.bp.blogspot.com/-2gbmug6spxE/V0XgFalWLXI/AAAAAAAAAO0/RN0Uo4A1rmwbVKXErfshYabwdhzAdOCmwCLcB/s72-c/Google-Play-Services-338x600.png" height="72" width="72" />
         <thr:total>0</thr:total>
</item>
</channel></rss>

i want to get the thumbnail url and i get this

Error: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

this is my code

WebRequest webRequest = WebRequest.Create(url);
WebResponse webResponse = webRequest.GetResponse();

        Stream stream = webResponse.GetResponseStream();
        XmlDocument xmlDocument = new XmlDocument();

        xmlDocument.Load(stream);

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
        //nsmgr.AddNamespace("thr", xmlDocument.DocumentElement.GetNamespaceOfPrefix("thr"));
        //nsmgr.AddNamespace("atom", xmlDocument.DocumentElement.GetNamespaceOfPrefix("atom"));
        //nsmgr.AddNamespace("blogger", xmlDocument.DocumentElement.GetNamespaceOfPrefix("blogger"));
        //nsmgr.AddNamespace("georss", xmlDocument.DocumentElement.GetNamespaceOfPrefix("georss"));
        //nsmgr.AddNamespace("gd", xmlDocument.DocumentElement.GetNamespaceOfPrefix("gd"));
        //nsmgr.AddNamespace("openSearch", xmlDocument.DocumentElement.GetNamespaceOfPrefix("openSearch"));
        nsmgr.AddNamespace("thr", "http://purl.org/syndication/thread/1.0");
        nsmgr.AddNamespace("atom","http://www.w3.org/2005/Atom");
        nsmgr.AddNamespace("blogger", "http://schemas.google.com/blogger/2008");
        nsmgr.AddNamespace("georss", "http://www.georss.org/georss");
        nsmgr.AddNamespace("gd", "http://schemas.google.com/g/2005");
        nsmgr.AddNamespace("openSearch","http://a9.com/-/spec/opensearchrss/1.0/");
        nsmgr.AddNamespace("media", "http://search.yahoo.com/mrss/");

        XmlNodeList itemNodes = xmlDocument.SelectNodes("rss/channel/item");

        for (int i = 0; i < itemNodes.Count; i++)
        {
            FeedItem feedItem = new FeedItem();

            if (itemNodes[i].SelectSingleNode("title") != null)
            {
                feedItem.Title = itemNodes[i].SelectSingleNode("title").InnerText;
            }
            if (itemNodes[i].SelectSingleNode("/media:thumbnail/url") != null)
            {

            feedItem.Image = itemNodes[i].SelectSingleNode("/media:thumbnail/url",nsmgr).InnerText;

            }

            if (itemNodes[i].SelectSingleNode("link") != null)
            {
                feedItem.Link = itemNodes[i].SelectSingleNode("link").InnerText;
            }

            if (itemNodes[i].SelectSingleNode("pubDate") != null)
            {
                feedItem.PubDate = Convert.ToDateTime(itemNodes[i].SelectSingleNode("pubDate").InnerText);
            }

            if (itemNodes[i].SelectSingleNode("author", nsmgr) != null)
            {
                feedItem.Author = itemNodes[i].SelectSingleNode("author", nsmgr).InnerText;
            }

            if (itemNodes[i].SelectSingleNode("category") != null)
            {
                feedItem.Category = itemNodes[i].SelectSingleNode("category").InnerText;
            }

            if (itemNodes[i].SelectSingleNode("description") != null)
            {
                feedItem.Description = itemNodes[i].SelectSingleNode("description").InnerText;
            }

            feedItemsList.Add(feedItem);
        }
    }
    catch (Exception)
    {
        throw;
    }

SomeOne can help please

Edited by Reverend Jim: Moved to programming forum

2
Contributors
1
Reply
12
Views
1 Year
Discussion Span
Last Post by rproffitt
0

Let's say you have the XML file. Why all that code when you just want to parse out the url in question?

That is, I've found MSFT XML to blow up on me so when I go to production now I either don't use it or publish it with warnings.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.