【发布时间】:2011-10-28 22:21:53
【问题描述】:
尝试使用
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 元素下列出我要查找的产品。
【问题讨论】: