[英]how to get the child nodes and group them from a parent node
我有一個XElement
對象,其結構如下。 我怎么會選擇所有的CalcConceptId
從子節點TestResults
其中根節點DataPointValue
屬性是不同的,並存儲為XElement
在陣列/表S? 我希望能夠將每個子對象存儲為另一個XElement
以便我可以遍歷它們,並從每個子SeriesAsOfDate
獲取SeriesAsOfDate
和數據節點。
<TestResults RSSD="123456">
<CalcConceptId Id="110" DataPointValue="10">
<SeriesAsOfDate Value="2013-07-10T00:00:00">
<Data AsOfDate="7/10/2013" ExpectedValue="1" />
<Data AsOfDate="7/3/2013" ExpectedValue="14" />
<Data AsOfDate="6/26/2013" ExpectedValue="55" />
</SeriesAsOfDate>
</CalcConceptId>
<CalcConceptId Id="110" DataPointValue="20">
<SeriesAsOfDate Value="2013-07-10T00:00:00">
<Data AsOfDate="7/10/2013" ExpectedValue="4" />
<Data AsOfDate="7/3/2013" ExpectedValue="34" />
<Data AsOfDate="6/26/2013" ExpectedValue="1" />
</SeriesAsOfDate>
</CalcConceptId>
</TestResults>
我認為您希望將所有CalcConceptId節點按DataPointValue分組,但是“ DataPointValue的不同之處”的含義還不清楚。
無論如何,這就是我想要的...
var calcConceptIdGroupedByDataPointValue =
doc.Descendants("CalcConceptId")
.GroupBy(calcConceptId => calcConceptId.Attribute("DataPointValue"));
我不確定100%...但是,如果我明白您的要求,您是否正在尋找呢?
//assuming the XElement is called Data:
var result =
data.Elements().GroupBy(x => int.Parse(x.Attribute("DataPointValue")))
.Select(g => g.First());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.