我刚开始学习 Linq to XML 的可能性,最近发现我可以像数据库一样查询 xml(我现在对它非常着迷)。
我的问题是如何查询 xml 文件并将结果保存在另一个 xml 文件中?:
string url = "employees.xml";
XElement employees= XElement.Load(url);
if (employees.Element("employee") != null)
{
var query = from f in employees.Element("employee").Elements("item").Take(10)
select new { Name = f.Element("name").Value, Surname= f.Element("surname").Value };
foreach (var feed in query)
{
//here... I like to write the result in a different xml file, I tried the
//common
doc.save("xmlout.xml");
}
}
非常感谢你的帮助,