我有一個XML文件,它看起來像這樣不同的屬性如何刪除從XML元素:使用的XDocument,當我們有多個同名的元素,但
<Applications>
<myApp>
<add key="ErrorDestinationEventLog" value="EventLog" />
<add key="version" value="5.0.0.0" />
<add key="DebugMode_RUN" value="true" />
</myApp>
</Applications>
所有元素都具有相同的元素名稱但不同屬性。 如何在C#中使用XDocument從一個xml中移除一個特定元素?
xd.Element("Applications").Element("myApp").Element(xe.Name).RemoveAll();
上述命令不起作用,因爲所有元素都具有相同的名稱。
是否有任何方法來識別一個元素,而不是它的名字? 如果是這樣,我該如何使用它從XDocument中刪除它?
您是否調試過代碼?你知道什麼.Element(「myApp」)正在返回嗎?只需要尋找更多有關你所看到的事情的信息。 – Jr0
感謝您的建議。我明白.Element(「myApp」)返回名稱爲「myApp」的第一個元素,對嗎? –