我目前有以下代码:
document.createElementNS("http://www.w3.org/2000/svg", "svg")
我期待;
XElement TEST = XElement.Parse(
@"<SettingsBundle>
<SettingsGroup Id=""QAVerificationSettings"">
<Setting Id=""RegExRules"">True</Setting>
<Setting Id=""RegExRules123"">
<RegExRule xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/Sdl.Verification.QAChecker.RegEx"">
<IgnoreCase>false</IgnoreCase>
</RegExRule>
</Setting>
</SettingsGroup>
</SettingsBundle>");
TEST.Elements("Setting").Remove();
var NEW = new XDocument( TEST );
var OUT = Directory.GetCurrentDirectory() + @"\_Texting.xml";
NEW.Save(OUT);
但没有删除。
答案 0 :(得分:1)
TEST.Elements("Setting")
...只会在根级别找到元素,但由于Settings
嵌套在SettingsGroup
下,因此更容易在树中所有节点中找到它们使用Descendants
。
TEST.Descendants("Setting").Remove();
...导致......
<SettingsBundle>
<SettingsGroup Id="QAVerificationSettings" />
</SettingsBundle>