473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Deseralizing RSS into a Class?

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.
Jul 21 '05 #1
2 1238
Kelly,

You need a schema for this. It won't work without one. I've used this:
http://apps.gotdotnet.com/xmltools/x.../overview.html to do similar
things; I'm sure you can get it to work with RSS as well.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Kelly Elias" <an*******@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
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.
Jul 21 '05 #2
You can use also RSS.NET
http://rss-net.sourceforge.net/
RSS.NET is an open-source .NET class library for RSS feeds. It provides a
reusable object model for parsing and writing RSS feeds. It is fully
compatible with RSS versions 0.90, 0.91, 0.92, and 2.0.1, implementing all
constructs.

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"Klaus H. Probst" <us*******@vbbox.com> wrote in message
news:#0**************@TK2MSFTNGP12.phx.gbl...
Kelly,

You need a schema for this. It won't work without one. I've used this:
http://apps.gotdotnet.com/xmltools/x.../overview.html to do similar things; I'm sure you can get it to work with RSS as well.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Kelly Elias" <an*******@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
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.

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Murat Tasan | last post by:
hi, i am having a small problem with constructing an inner class. i am using an inner class (and not a static nested class) because the methods of the inner class need access to the enclosing...
2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
2
by: Gabriel Genellina | last post by:
Hi In the following code sample, I have: - a Worker class, which could have a lot of methods and attributes. In particular, it has a 'bar' attribute. This class can be modified as needed. - a...
1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
2
by: Kelly Elias | last post by:
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,...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.