473,398 Members | 2,403 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,398 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 1240
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.