我的 XML 文件有问题。
<?xml version="1.0" encoding="UTF-8"?>
<config>
<settings>
<excelFilePath>C:\Temp\</excelFilePath>
<mailHost>smtp</mailHost>
<mailPort>25</mailPort>
<mailFrom>me@test.com</mailFrom>
<keepInCopy>
<mailCC>email1@test.com</mailCC>
<mailCC>email2@test.com</mailCC>
<mailCC>email3@test.com</mailCC>
</keepInCopy>
<mailSubject>My Mail subject</mailSubject>
<mailBodyPath>Templates\Template1.htm</mailBodyPath>
</settings>
</config>
在实践中,我只需要删除所有标签“mailCC”。我目前正在尝试这个 C# 代码,但没有任何反应:
XmlDocument xml = new XmlDocument();
xml.Load(FilePath);
XmlNodeList xnList = xml.GetElementsByTagName("mailCC");
foreach (XmlNode xn in xnList)
{
xn.RemoveChild(xn.FirstChild);
xml.Save(FilePath);
}
请问你能帮帮我吗?