0
<categories>
<category text="Arts">
  <category>
        <category text="Design"/>
        <category text="Visual Arts"/>
   <category>
</category>
<category text="Business">
    <category>
        <category text="Business News"/>
        <category text="Careers"/>
        <category text="Investing"/>
   </category>
</category>
<category text="Comedy"/>
</categories>

現在私は使用しています

xDoc.Descendants("category").Where(a => a.Attribute("text").Value == "Arts").Descendants("category")

上記のコードは、属性「Arts」を持つカテゴリからすべてのカテゴリ要素を返します。私が欲しいのは、属性「Arts」を持つカテゴリのすぐ下のカテゴリのノードのみです。テキスト属性のデザインと視覚芸術のカテゴリではありません。以下のようなカテゴリノード全体が必要です

 <category>
    <category text="Design"/>
    <category text="Visual Arts"/>
 <category>
4

1 に答える 1

1

Here you go, hope you still need this:

    string category = "Business";
    var children = xDoc.Root.Elements("category").Where(a => a.Attribute("text").Value == category).Elements();
于 2012-12-21T22:44:01.157 に答える