前几天在搞rss的解析,碰到一些问题

     现在RSS很流行,一度风行于整个互联网,的确,他给我们带来了很大的改变和方便!RSS也分很多版本,rss.1.0.rss2.0比较多,还有atom格式的!
   在解析的时候给我带来了麻烦,由于本人没有怎么研究过xml和相关的解析工作,所以碰到很多问题,目前能成功解析rss2.0。
   顶部的一些解析(暂时这么叫吧,我也不知道叫什么)

 1 None.gif private   void  GetRssHead(XmlDocument doc)
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif            //XmlDocument doc = new XmlDocument();
 4InBlock.gif            //doc.LoadXml(this.RssXmlStr);
 5InBlock.gif            XmlElement elem = (XmlElement)doc.DocumentElement.FirstChild;
 6InBlock.gif            this.headtitle=elem.SelectSingleNode("title").InnerText;
 7InBlock.gif            this.headurl=elem.SelectSingleNode("link").InnerText;
 8InBlock.gif            this.headdescription=elem.SelectSingleNode("description").InnerText;
 9InBlock.gif
10ExpandedBlockEnd.gif        }
内容的解析:
 1 None.gif      private   void  ParseItems()
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif            XmlDocument doc = new XmlDocument();
 4InBlock.gif            doc.LoadXml(this.RssXmlStr);
 5InBlock.gif            XmlNodeList nodeList;
 6InBlock.gif            XmlElement root = doc.DocumentElement;
 7InBlock.gif            nodeList = root.GetElementsByTagName("item");
 8InBlock.gif            for(int n=0;n<nodeList.Count;n++)
 9ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
10InBlock.gif                listtitle.Add(nodeList[n].SelectSingleNode ("title").InnerText);
11InBlock.gif                listlink.Add(nodeList[n].SelectSingleNode ("link").InnerText);
12InBlock.gif                listdescription.Add(nodeList[n].SelectSingleNode ("description").InnerText);
13ExpandedSubBlockEnd.gif            }

14ExpandedBlockEnd.gif        }
但是对于rss1.0我目前只能这样处理:
1 None.gif                  // 头部
2 None.gif                 nodeList  =  root.GetElementsByTagName( " channel " );
3 None.gif                 this .headtitle = nodeList[ 0 ].ChildNodes[ 0 ].InnerText;
4 None.gif                 this .headurl = nodeList[ 0 ].ChildNodes[ 1 ].InnerText;
5 None.gif                 this .headdescription = nodeList[ 0 ].ChildNodes[ 2 ].InnerText;
6 None.gif
不能用SelectSingleNode来取元素,这样RSS变了顺序就不行了,还有Atom格式的一样也没处理好!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值