<?xml version="1.0" encoding="utf-8" ?><rss> <channal> <title>音乐新闻</title> <content> <item>这是第一个音乐新闻</item> <item>这是第二个音乐新闻</item> </content> </channal> <channal> <title>体育新闻</title> <content> <item>这是第一个体育新闻</item> <item>这是第二个体育新闻</item> </content> </channal></rss>
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Xml;namespace Iofile{ public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { treeView1.Nodes.Clear(); XmlDocument myxml = new XmlDocument(); myxml.Load(@"C:\Documents and Settings\Administrator\my documents\visual studio 2010\Projects\Iofile\Iofile\Tv.xml"); XmlNode node=myxml.DocumentElement; TreeNode trnode = new TreeNode(); foreach (XmlNode node1 in node.ChildNodes) { foreach (XmlNode node2 in node1.ChildNodes) { switch (node2.Name) { case "title": trnode = treeView1.Nodes.Add(node2.InnerText); break; case "content": foreach (XmlNode node3 in node2.ChildNodes) { if (node3.Name == "item") { trnode.Nodes.Add(node3.InnerText); } } break; } } } } }}
联系客服