G
Guest
I am trying to build an RSS class that takes information such as this: http://www.msdn.microsoft.com/rss.xml and deseralizes it into a class. I basically want the channel information such as title, description etc, but I would like a class created to function as the interface into the data. Here is my attempt:
public class RSSFeed
{
public string title;
public string link;
public string description;
public string language;
public string copyright;
public string managingEditor;
public string webMaster;
public string ubDate;
public string lastBuildDate;
public string category;
public string generator;
public string ttl;
public string rating;
public RSSFeed()
{
}
public static RSSFeed deseralize(string url)
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
RSSFeed feed = new RSSFeed();
XmlSerializer serializer = new XmlSerializer(feed.GetType());
feed = (RSSFeed)serializer.Deserialize(responseStream);
response.Close();
responseStream.Close();
return feed;
}
}
-------------------
The problem is in the Deseralize line. The XmlSeralizer throws an exception when I attempt to do this. I'm not sure why. I have tried many different ways to feed it the data without success.
There seems to be some junk chars at the front of the stream like "o:?" I'm not sure why.
But it also fails when I try a different RSS feed from slashdot (http://slashdot.org/index.rss) without the junk characters.
(And yes I do realize that I probably need XmlElement Attributes for the variables in my class to call into "//rss/channel" but I left that out for ease of reading.)
Anyone have any suggestions, or has anyone got a class that deseralizes such as this? As a workaround i can obviously load the XML into a DOM then use XPath to pull the parts I need and assign it to the variables, but that approach does not seem as elegant.
public class RSSFeed
{
public string title;
public string link;
public string description;
public string language;
public string copyright;
public string managingEditor;
public string webMaster;
public string ubDate;
public string lastBuildDate;
public string category;
public string generator;
public string ttl;
public string rating;
public RSSFeed()
{
}
public static RSSFeed deseralize(string url)
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
RSSFeed feed = new RSSFeed();
XmlSerializer serializer = new XmlSerializer(feed.GetType());
feed = (RSSFeed)serializer.Deserialize(responseStream);
response.Close();
responseStream.Close();
return feed;
}
}
-------------------
The problem is in the Deseralize line. The XmlSeralizer throws an exception when I attempt to do this. I'm not sure why. I have tried many different ways to feed it the data without success.
There seems to be some junk chars at the front of the stream like "o:?" I'm not sure why.
But it also fails when I try a different RSS feed from slashdot (http://slashdot.org/index.rss) without the junk characters.
(And yes I do realize that I probably need XmlElement Attributes for the variables in my class to call into "//rss/channel" but I left that out for ease of reading.)
Anyone have any suggestions, or has anyone got a class that deseralizes such as this? As a workaround i can obviously load the XML into a DOM then use XPath to pull the parts I need and assign it to the variables, but that approach does not seem as elegant.