更新时间:2023-11-23 22:12:58
请根据您的要求尝试以下代码...
Please try below code for your requirement...
XDocument xmlDoc = XDocument.Load(filePath);
bool isExists = (from data in xmlDoc.Element("appsettings")
select data).Any();
if (!isExists)
{
XmlElement parent = xmlDoc.CreateElement("configuration");
//Now find that appSettings node and append it to parent Element
}
//Delete Node
XmlNodeList newXMLNodes = xmlDoc.SelectNodes("/configuration/appsettings");
foreach (XmlNode child in newXMLNodes)
{
child.ParentNode.RemoveAll();
}