读取xml文件信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
static void Main(string[] args)
        {
            XmlTextReader reader = new XmlTextReader(@"D:\zy\visual studio 2010\第11周\十一假期\MVC\Insigma.Xml\Xml\XMLFile1.xml");
            while (reader.Read())
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    reader.Read();
                    if (reader.NodeType == System.Xml.XmlNodeType.Text)
                    {
                        Console.WriteLine(reader.Value);
                    }
                }
            }
            Console.ReadKey();
        }

 xml文件:

复制代码
1 <students>
2   <student>
3     <name>张杰</name>
4     <age>20</age>
5     <gender>男</gender>
6   </student>
7 </students>
View Code
复制代码

 运行结果:

posted on   zy`  阅读(199)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示