把我从昨天到今天进行的学习内容贴出来,大家一起分析一下吧~

ilmself0451 2005-03-20 06:21:01
// ------------------------------------------------
// 这以下是 RSSFeed.cs
using System;
using System.Xml;
using System.IO;
using System.Net;
using System.Text;

namespace RWO.RSSBase
{
// RSS版本信息
// 注意,此结构是一个枚举类型,列表中的元素用","分隔而不使用";"
public enum RSSVersion
{
version_Unknow = 0,
version_0_91 = 1,
version_0_92 = 2,
version_2_00 = 31
}

// RSSItem结构体
public struct RSSItem
{
string Title;
string Description;
DateTime pubDate;
Uri Link;
}

// RSS头信息结构体
public struct RSSHeader
{
string Title;
Uri Link;
string Description;
string Language;
string Copyright;
string managingEditor;
string webMaster;
DateTime lastBuildDate;
}

/// <summary>
/// RSSItemCollection类
/// </summary>
public class RSSItemCollection : System.Collections.CollectionBase
{
//private System.Collections.ArrayList List = new System.Collections.ArrayList();

public RSSItem[] this [ int index ]
{
get
{ return List[index]; }
set
{ List[index] = value; }
}


// 添加一个RSS项目
public int Add(RSSItem value)
{
return List.Add(value);
}

// 索引一个项目
public int IndexOf(RSSItem value)
{
return List.IndexOf(value);
}

// 插入一条项目
public void Insert(int index, RSSItem value)
{
List.Insert(index, value);
}

// 删除一条项目
public void Remove(RSSItem value)
{
List.Remove(value);
}

// Contains
public bool Contains(RSSItem value)
{
return List.Contains(value);
}
} // RSSItemCollection结束

public class RSSFeed : XMLParser
{
public RSSFeed()
{
//
// TODO: 在此处添加构造函数逻辑
//
this.myRSSVersion = RSSVersion.version_Unknow;
}

// 属性列表
private RSSVersion myRSSVersion;
private RSSItemCollection myRSSItems;
private RSSHeader myRSSHeader;

// 定义RSS版本属性的读取操作
public RSSVersion version
{
get { return this.myRSSVersion; }
set { this.myRSSVersion = value; }
}

// 定义RSS项目属性的读取操作
public RSSItem[] Item
{
get { return myRSSItems[index]; }
set { this.myRSSItems[index] = value; }
}

// 定义项目列表属性的读取操作
public RSSItemCollection Items
{
get { return this.myRSSItems; }
set { this.myRSSItems = value; }
}

// 定义对RSS头信息的读取操作
public RSSHeader Header
{
get { return this.myRSSHeader; }
set { this.myRSSHeader = value; }
}

//未完,接下篇..
...全文
232 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ilmself0451 2005-03-22
  • 打赏
  • 举报
回复
汗~CSDN让我失望了~
yaopeng117 2005-03-22
  • 打赏
  • 举报
回复
好多,头看晕了。
haibuo1981 2005-03-22
  • 打赏
  • 举报
回复
你连什么问题都没说,让别人怎么帮你
ilmself0451 2005-03-21
  • 打赏
  • 举报
回复
哦~我是说CSDN呀,CSDN不是中国最大的程序员网站吗?怎么我的问题都没有人帮帮忙呢?

我是真的不行了~-_-!
ArLi2003 2005-03-21
  • 打赏
  • 举报
回复
http://www.codeproject.com/csharp/RssReader.asp

这里不是中国最大的程序员网站,中国根本没这种网站,不管是名义上还是责任上。因为国内的程序员太忙了,忙老婆忙泡面忙工作。。。
ilmself0451 2005-03-21
  • 打赏
  • 举报
回复
怎么,没有人帮帮我吗?我晕了,中国最大的程序员网站呀~不能见死不救啊~
ilmself0451 2005-03-21
  • 打赏
  • 举报
回复
程序不能通过编译呀~
ilmself0451 2005-03-20
  • 打赏
  • 举报
回复
程序里面有问题呀,都不能通过编译呀~
athossmth 2005-03-20
  • 打赏
  • 举报
回复
你的问题是什么?
fansihong 2005-03-20
  • 打赏
  • 举报
回复
用那么复杂么?
ilmself0451 2005-03-20
  • 打赏
  • 举报
回复
还是没有人来看吗?55555555
ilmself0451 2005-03-20
  • 打赏
  • 举报
回复
UP一下~大家一起来看看啊~
ilmself0451 2005-03-20
  • 打赏
  • 举报
回复
// 接上文
// 读取RSS版本信息的方法
private RSSVersion getRSSVersion()
{
XmlNode myrootNode;
XmlAttribute versionAttribute;
RSSVersion myRSSVersion;

myRSSVersion = RSSVersion.version_Unknow;
myrootNode = fetchNode ( Document.ChildNodes ,"rss");
versionAttribute = fetchAttribute (myrootNode ,"version");
switch(versionAttribute.Value)
{
case "0.91":
myRSSVersion = RSSVersion.version_0_91;
break;
case "0.92":
myRSSVersion = RSSVersion.version_0_92;
break;
case "2.00":
myRSSVersion = RSSVersion.version_2_00;
break;
}
return myRSSVersion;
}

// 从本地文件中读取
public void Load(string filename)
{
base.LoadFromFile(filename);
PopulateMembers();
}

// 从Http中读取
public void LoadFromHttp(string Url)
{
base.LoadFromUrl(Url);
PopulateMembers();
}

// 读取最新信息
private void PopulateMembers()
{
XmlNode myNode, myItemNode;
int i;
this.myRSSHeader.Copyright = "";
this.myRSSHeader.Descripton = "";
this.myRSSHeader.Language = "";
this.myRSSHeader.Title = "";
this.myRSSHeader.webMaster = "";
this.myRSSHeader.managingEditor = "";
this.myRSSHeader.lastBuildDate = null;
// 这里怎么转换呀??
// 父类怎么进行使用呢?使用base就可以了。

base.DocumentRoot = this.fetchNode ( this.Document.ChildNodes ,"rss");
base.DocumentRoot = this.fetchNode ( base.DocumentRoot.ChildNodes,"channel");
this.myRSSVersion = this.getRSSVersion ();

myNode = fetchNode(base.DocumentRoot.ChildNodes, "title");
if ( myNode == null )
this.myRSSHeader.Title = myNode.InnerText;
myNode = fetchNode(base.DocumentRoot.ChildNodes, "link");
if ( myNode == null )
this.myRSSHeader.Link = new Uri(myNode.InnerText);
myNode = fetchNode(base.DocumentRoot.ChildNodes, "description");
if ( myNode == null )
this.myRSSHeader.Link = myNode.InnerText;
myNode = fetchNode(base.DocumentRoot.ChildNodes, "language");
if ( myNode == null )
this.myRSSHeader.Link = myNode.InnerText;
myNode = fetchNode(base.DocumentRoot.ChildNodes, "copyright");
if ( myNode == null )
this.myRSSHeader.Link = myNode.InnerText;
myNode = fetchNode(base.DocumentRoot.ChildNodes, "managingEditor");
if ( myNode == null )
this.myRSSHeader.Link = myNode.InnerText;
myNode = fetchNode(base.DocumentRoot.ChildNodes, "webMaster");
if ( myNode == null )
this.myRSSHeader.Link = myNode.InnerText;
myNode = fetchNode(base.DocumentRoot.ChildNodes, "lastBuildDate");
if ( myNode == null )
this.myRSSHeader.Link = DateTime.Parse(myNode.InnerText);

this.myRSSItems.Clear();

for(i=0;base.DocumentRoot.ChildNodes.Count-1;i++)
{
if ( base.DocumentRoot.ChildNodes[i].Name == "item" )
{
myItemNode = base.DocumentRoot.ChildNodes[i];
RSSItem myItem;
myItem.pubDate = null;
myNode = fetchNode(myItemNode.ChildNodes, "description");
if ( myNode == null )
myItem.Description = myNode.InnerText;
myNode = fetchNode(myItemNode.ChildNodes, "title");
if ( myNode == null )
myItem.Title = myNode.InnerText;
myNode = fetchNode(myItemNode.ChildNodes, "link");
if ( myNode == null )
myItem.Link = Uri(myNode.InnerText);
myNode = fetchNode(myItemNode.ChildNodes, "pubDate");
if ( myNode == null )
myItem.pubDate = DateTime.Parse (myNode.InnerText);
switch(this.myRSSVersion )
{
case RSSVersion.version_0_91:
break;
case RSSVersion.version_0_92:
break;
case RSSVersion.version_2_00:
break;
}
this.myRSSItems.Add(myItem);
}
}
}
}
}
// RSSFeed.cs结束
// ------------------------------------------------
// ------------------------------------------------
// 以下是XMLParser.cs
using System;
using System.Xml;
using System.Net;
using System.Text;
using System.IO;

namespace RWO.RSSBase
{
public class XMLParser
{
protected XmlDocument Document;
protected XmlNode DocumentRoot;


protected void LoadFromText(string xml)
{
this.Document.LoadXml(xml);
}

protected void LoadFromFile(string filename)
{
this.Document.Load(filename);
}

protected void LoadFromUrl(string Url)
{
HttpWebRequest myRequest;
string responseText = null;
// Byte[] res;
myRequest = WebRequest.Create(Url);
HttpWebResponse MyResponse = myRequest.GetResponse();
Stream receiveStream = MyResponse.GetResponseStream();
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
responseText = readStream.ReadToEnd();
MyResponse.Close();
readStream.Close();
this.Document.LoadXml(responseText);
}

protected void SaveToFile(string filename)
{
this.Document.Save(filename);
}

protected XmlNode fetchNode( XmlNodeList list, string nodeName)
{
int i;
for(i=0;i<=list.Count-1;i++)
{
if(list.Item(i).Name==nodeName)
return list.Item(i);
}
}

protected XmlAttribute fetchAttribute( XmlNode node, string attributeName)
{
int i;
for(i=0;i<=node.Attributes.Count-1;i++)
{
if(node.Attributes[i].Name==attributeName)
{
return node.Attributes[i];
}
}
}



public XMLParser()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
}
// XMLParser.cs结束
//-------------------------------------------------------
这是一个使用.net进行查看RSS信息的组件的代码。
现在的问题很多呀~朋友们,帮忙看看呀。对了,忘了说,这个程序原来是codeproject上的例子。但是VB.net写的。让我改写了。初学者,弄的不明白,大家一起来看看吧。
{vb中的源码编译通过。但改写成c#的就出问题了~}

原来内容的地址:http://www.codeproject.com/aspnet/rssViewer.asp 有兴趣的朋友可以去看看原文的VB的源码。

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧