C# 用Linq的方式实现对Xml文件的基本操作(创建xml文件、增删改查xml文件节点信息)
http://www.cnblogs.com/mingmingruyuedlut/archive/2011/01/27/1946239.html
修改了一下里面一部分
try
{
// 定义并从xml文件中加载节点(根节点)
XElement rootNode = XElement.Load(xmlPath);
var query = from rssFeed in rootNode.Descendants( " User " )
select new
{
name = rssFeed.Element( " name " ).Value,
password = rssFeed.Element( " password " ).Value,
description = rssFeed.Element( " description " ).Value
};
foreach (var item in query)
{
Console.WriteLine( " name: " + item.name + "" );
Console.WriteLine( " password: " + item.password);
Console.WriteLine( " description: " + item.description);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
{
// 定义并从xml文件中加载节点(根节点)
XElement rootNode = XElement.Load(xmlPath);
var query = from rssFeed in rootNode.Descendants( " User " )
select new
{
name = rssFeed.Element( " name " ).Value,
password = rssFeed.Element( " password " ).Value,
description = rssFeed.Element( " description " ).Value
};
foreach (var item in query)
{
Console.WriteLine( " name: " + item.name + "" );
Console.WriteLine( " password: " + item.password);
Console.WriteLine( " description: " + item.description);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
备份一下: