xml解析
时间:2011-04-12 来源:uwking
List<string> xmlstr = new List<string>();
string path = @"xml文件"; //如D:\软件文档\Player\Project\48001\TaskList.xml
XmlNodeReader reader = null;
try
{
XmlDocument xd = new XmlDocument();
xd.Load(path);
reader = new XmlNodeReader(xd); //创建新的XML reader
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element://判断读到的是否为节点
xmlstr.Add(reader.Name);
break;
case XmlNodeType.Text://判断读到的是否为节点值
xmlstr.Add(reader.Value);
break;
default:
break;
}
}
}
catch (Exception e)
{
System.Console.WriteLine("Read XML File Error:" + e.Message + e.StackTrace);
}
finally
{
if (reader != null)
{
reader.Close();
}
}