Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[WP7]XML, youtube feeds, C# and namespaces problems.

xml namespace

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 JackPanzer

JackPanzer

    CC Newcomer

  • Member
  • PipPip
  • 16 posts

Posted 12 October 2012 - 09:42 AM

Hello everyone!

As the title of the post says, I'm having some problems when downloading and parsing a youtube XML feed. to be more precise, I'm testing with this one:

h**ps://gdata.youtube.com/feeds/api/standardfeeds/most_recent

Due to I'm coding it for Windows Phone 7, I used a WebClient object to download the feeds. After I download the feed, I parse it into a new XML document, but when I try to access to any <entry> element, I throws me a null reference. First I will post part of the xml feed (is a huge file, so I'll only post part of it)

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:gml='http://www.opengis.net/gml'
xmlns:yt='http://gdata.youtube.com/schemas/2007'
xmlns:georss='http://www.georss.org/georss'>

<id>http://gdata.youtube.com/feeds/api/standardfeeds/most_recent</id>
...

if (e.Error != null)
		 {
			 MessageBox.Show("No se ha podido obtener la informaciĆ³n de Internet");
			 return;
		 }
		 else
		 {
			 //+ element.Name {{http://www.w3.org/2005/Atom}entry} System.Xml.Linq.XName
			 XNamespace name = "http://www.w3.org/2005/Atom";
			 XmlReader reader = XmlReader.Create(new StringReader(e.Result));
			 XDocument doc = Xdocument.Load(reader);
			 var list = doc.Descendants(name + "entry"); // Gives me an empty list
		 }

I'm pretty sure that I'm in the right way because I've been searching in google for it and yet found this same solution, but still throws me a null reference.

As a possible workaround I was thinking in erasing all the xmlns fields in <feed> with regex and then parse the whole string in the XDocument, but I'm worried about the CPU and memory consumption because knowing that I'm coding the application for a mobile platform the OS can forze close the application without advice.

If there is some mistake, wich part of the code is wrong and what can I do to fix it? Are there other workarounds?

Thanks for your time.

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts

Posted 16 December 2012 - 07:45 AM

In one of the projects where I created an 'RSS Crawler' where I needed to read and parse RSS feed. I used XPathDocument and XPathNavigator. I hope it will work for you as well. Can you give a try and get us with your feedback?




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download