exportDoc.Root.Elements("string").Where(node => !(node.Element("product").HasElements) || node.Element("product").Element("type").Value != product).Remove();
删除我的XML文档中的节点,其中product
字符串我在寻找不会发生。这是我的XML结构的一个示例:
<root>
<string id = "Hithere">
<product>
<type>orange</type>
<type>yellow</type>
<type>green</type>
<product>
<element2/>
<element3/>
</string>
<string id ="...">
...
...
</root>
所以我需要每个string
元件的product
元件之下,并在每个在其中的type
元素来看看是否串product
(输入的值,以该方法在哪里包含)发生。目前,如果我要搜索的product
字符串与第一个type
元素的值匹配,它看起来像我的代码只会删除该节点。
整个问题是要删除此xdoc中没有我要查找的产品的product
元素下的所有字符串节点。
正是我在找的东西。谢谢! –