2012-12-14 62 views
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") 

上面的代碼返回我的所有類別元素的類與屬性「藝術」 我想要的只是屬於「藝術」屬性類別下的類別節點 不是具有文本屬性設計和視覺藝術的類別。我要像下

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

回答

1

在這裏你去全品類節點,希望你仍然需要這樣的:

string category = "Business"; 
    var children = xDoc.Root.Elements("category").Where(a => a.Attribute("text").Value == category).Elements(); 
相關問題