本文摘自PHP中文网,作者黄舟,侵删。
C#解析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 32 33 34 35 36 37 38 39 40 41 42 | XmlNodeReader reader = null ;
try
{
XmlDocument xd = new XmlDocument();
xd.Load(filename);
reader = new XmlNodeReader(xd);
string nodeType = null ;
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
nodeType = reader.Name;
break ;
case XmlNodeType.Text:
switch (nodeType)
{
case ROOT:
rootValue = reader.Value;
break ;
default :
break ;
}
break ;
default :
break ;
}
}
}
catch (Exception e)
{
System.Console.WriteLine( "Read XML File Error:" + e.Message + e.StackTrace);
}
finally
{
if (reader != null )
{
reader.Close();
}
}
......................
最后不要忘记把reader close 掉
|
这样其实可以使用这种方法来减少命令行参数的个数,现在只需要加一个文件名即可。但是要在文件中写好参数
以上就是C#解析XML文件的代码实例分享的详细内容!
相关阅读 >>
C# clickonce部署报错解决方法
详细介绍C#语言中字符类char的使用方法总结
关于C#中三个关键字params,ref,out的详细介绍
C# 2.0 specification (四)
用C#向word文档插入和隐藏段落的方法介绍
C#基础入门-关键字的介绍
c#cs与bs数据请求交换
C#兼容各大浏览器的文件下载实例详解
如何在C#中使用bogus去创建模拟数据
C# system.drawing.region类的方法使用(图解)
更多相关阅读请进入《C#》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » C#解析XML文件的代码实例分享