follow my heart...
分类:
2006-12-15 13:32:26
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"); |
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 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); } |