C # perform basic operations on Xml files in the form of Linq (create xml files, add, delete, modify, and query xml file node Information)
Http://www.cnblogs.com/mingmingruyuedlut/archive/2011/01/27/1946239.html
Modified some of them.
Try
{
// Define and load the node (root node) from the xml file)
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 ());
}
Backup:
/Files/hantianwei/LinqXML.rar