Label + TextBox (txtURL):輸入 RSS 連結Button (bnRead):執行讀取TreeView (treeRSS):顯示新聞列表
public class rss
{
public struct Channel
{
public string Title;
public Hashtable Items;
}
public struct Item
{
public string Title;
public string Description;
public string Link;
}
}
Channel.Items 以 Hashtable 儲存多筆 Item,Key 使用 Count 保證唯一。
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)
{
for (int i = 0; i < Node.ChildNodes.Count; i++)
{
if (Node.ChildNodes[i].Name == Name && Node.ChildNodes[i].ChildNodes.Count > 0)
return Node.ChildNodes[i];
}
return null;
}
XmlNode rssNode = FoundChildNode(xmlDoc, "rss");
XmlNode channelNode = FoundChildNode(rssNode, "channel");