請問怎么在LINQ FOR XML只返回類似主從表的信息

請問如何在LINQ FOR XML只返回類似主從表的信息?
本帖最后由 gxpotato 于 2012-03-01 14:02:15 编辑 假設有個XML
<root>
  <man>
    <home>
      <children1 group_name="brother">
 <child name="tom1" />
 <child name="jack1" />
      </children1>
      <children2 group_name="sister">
 <child name="tom2" />
 <child name="jack2" />

      </children2>
    </home>
  </man>
</root>


我怎麼用LINQ FOR XML查詢child 的 attribute name包含 “tom”,然後返回一條類似這樣的資料?類似主從表的
<home>
<children1 group_name="brother">
<child name="tom" />
</children>
<children2 group_name="sister">
 <child name="tom2" />
</children2>

</home>

我只要返回children1,就會把所有child都帶過來,太鬱悶了,搞了半天沒搞定。。。我只想要一個child節點,而不是所有child節點。
------最佳解决方案--------------------
找到 不包含tom 的节点,并且删除它们,剩余就是你要的了
类似:
XElement xe=XElement.Parse();
xe.Descendants("child ").Where(w=>!w.Attribute("name").value.Contains("tom")).Remove();
// xe 就差不多是你想要的吧
------其他解决方案--------------------
我先試試,我的結貼率是很高的。我希望付出的人都有回報。
------其他解决方案--------------------
怎麼把兩個字符型的在lamba表達式裏面轉為整型來判斷呢?

xe.Descendants("child ").Where(w=>!w.Attribute("name").value.Contains("tom")).Remove();

如果我的xml裏面的name是數字,但是用字符來保存,在lamba裏面怎麼再轉為int?試了一下,總是搞不定。