VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之XML与TreeView(2)

  2 解析XML文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
XmlDocument doc = new XmlDocument();
          doc.Load("XMLFile1.xml");
          XmlNode xn = doc.DocumentElement;
          foreach (XmlNode item in xn.ChildNodes) {
 
              //foreach (XmlNode item1 in item.ChildNodes) {
 
              //    switch (item1.Name) {
                  
              //        case "Name":
              //            Console.WriteLine("电脑的名字是:" + item1.InnerText);
              //            break;
              //        case "Price":
              //            Console.WriteLine("电脑的价格是:" + item1.InnerText);
              //            break;
              //        case "CPU":
              //              Console.WriteLine("电脑的CPU是:" + item1.InnerText);
              //            break;
                  
                 
                  
              //    }
              
              
              //}
              Console.WriteLine(item.Attributes["typr"].Value);
              Console.WriteLine("电脑的名字是:" + item["Name"].InnerText);
              Console.WriteLine("电脑的Price是:" + item["Price"].InnerText);
              Console.WriteLine("电脑的CPU是:" + item["CPU"].InnerText);
          }
          Console.ReadKey();

相关教程