C#?????LINQ????XML?????????????????
???????????? ???????[ 2014/7/3 14:03:25 ] ????????C# net
??????????XML??????????????XmlDocument???????ЩС???????????????????????????????4M??XML??????????????????????????????????Web????o??????????ж????????????????????????CPU??ú????????????д??????????????????????????????????????????????£?
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(ConfigFilePath);
XmlNodeList nodeList = xmlDocument.SelectNodes("/System/add");
foreach (XmlNode node in nodeList)
{
if (node.Attributes["key"] != null)
{
if (node.Attributes["key"].Value.Equals(key?? StringComparison.CurrentCultureIgnoreCase))
{
node.RemoveAll();
}
}
}
|
?????????????System??add????????y???key??????????????????????????????????з??????????4M?????????1?????????????????????????????????????
??????????????????XML???????????????LINQ TO XML??????????????????????£?
????XElement rootNodes = XDocument.Load(ConfigFilePath).Root;
????rootNodes.Elements("add").Where(el => el.Attribute("key").Value.Equals(key)).Remove();
????????????÷??????????????200?????????????????????????????
????????????????????·??????????????
private static void DeleteXmlNodeInformation(string xmlPath)
{
try
{
//???岢??xml????м??????????
XElement rootNode = XElement.Load(xmlPath);
//??????: ???ID?????????"999999"??????User???
IEnumerable<XElement> targetNodes = from target in rootNode.Descendants("User")
where target.Attribute("ID").Value.Equals("999999")
select target;
//???????????е???????????δ?????????????????
targetNodes.Remove();
//?????xml????????
rootNode.Save(xmlPath);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11