public class rss { public struct channel { public string title; public hashtable items; } public struct item { public string title; public string description; public string link; } } |
xmltextreader reader = new xmltextreader(url); xmlvalidatingreader valid = new xmlvalidatingreader(reader); valid.validationtype = validationtype.none; xmldocument xmldoc= new xmldocument(); xmldoc.load(reader); |
private xmlnode foundchildnode(xmlnode node,string name) { xmlnode childlnode = null; for (int i=0;i < node.childnodes.count;i++) { if ( node.childnodes[i].name == name && node.childnodes[i].childnodes.count > 0 ) { childlnode = node.childnodes[i]; return childlnode; } } return childlnode; } xmlnode rssnode = foundchildnode(xmldoc,"rss"); xmlnode channelnode = foundchildnode(rssnode,"channel"); |
然后我们就可以遍历它的子节点,根据子节点的name属性,读取我们需要的信息。
rss.channel channel=new rss.channel(); channel.items=new hashtable(); { switch ( channelnode.childnodes[i].name ) { case "title": { channel.title = channelnode.childnodes[i].innertext; break; } case "item": { rss.item item=this.getrssitem(channelnode.childnodes[i]); channel.items.add(channel.items.count,item ); break; } } } |
private void viewrss(rss.channel channel) { treerss.beginupdate(); treerss.nodes.clear(); treenode channelnode=treerss.nodes.add(channel.title ); channelnode.tag=""; for (int i=0;i <channel.items.count ;i++) { rss.item item=(rss.item)channel.items[i]; treenode itemnode=channelnode.nodes.add(item.title ); itemnode.tag=item.link; } treerss.expandall(); treerss.endupdate(); } |
private void treerss_afterselect(object sender, system.windows.forms.treevieweventargs e) { treenode itemnode=e.node ; string url=itemnode.tag.tostring(); if (url.length!=0) system.diagnostics.process.start( url); } |
新闻热点
疑难解答