サンプルXML:
<PTC_FareBreakdowns>
<PTC_FareBreakdown>
<PassengerTypeQuantity Code="ADT" Quantity="1" />
<FareBasisCodes>
<FareBasisCode>RGOSAVE</FareBasisCode>
</FareBasisCodes>
<PassengerFare>
<BaseFare Amount="4400" CurrencyCode="INR" />
<Taxes>
<Tax Amount="233" CurrencyCode="INR" TaxCode="OC" TaxGroupCode="SF" TaxGroupName="Taxes &amp; Fees" />
<Tax Amount="218" CurrencyCode="INR" TaxCode="OC" TaxGroupCode="SF" TaxGroupName="Taxes &amp; Fees" />
<Tax Amount="3500" CurrencyCode="INR" TaxCode="YQ" TaxGroupCode="SF" TaxGroupName="Taxes &amp; Fees" />
<Tax Amount="440" CurrencyCode="INR" TaxCode="OC" TaxGroupCode="SF" TaxGroupName="Taxes &amp; Fees" />
<Tax Amount="173" CurrencyCode="INR" TaxCode="OC" TaxGroupCode="SF" TaxGroupName="Taxes &amp; Fees" />
<Tax Amount="0" TaxCode="B2BMarkup" />
</Taxes>
<TotalFare Amount="8964" CurrencyCode="INR" />
<Markups>
<Markup Amount="0.0000" CurrencyCode="INR" Description="0.0 for client - 26472" MarkupCode="DisplayMarkup" Type="M" />
<Markup Amount="0" CurrencyCode="INR" Description="0.0 % on base fare for client - " MarkupCode="DisplayMarkup" MarkupType="M" Type="M" />
<Markup Amount="0" Description="0.0% on fule surcharge 3500.0for client" MarkupCode="DisplayMarkup" MarkupType="M" Type="M" />
</Markups>
</PassengerFare>
</PTC_FareBreakdown>
</PTC_FareBreakdowns>
LINQ、私はこれまで試しましたが、
var Adult = from Main in xd.Descendants(ns + "PTC_FareBreakdown")
from Sub1 in Main.Elements(ns + "PassengerTypeQuantity")
where Sub1.Attribute("Code").Value == "ADT"
from Sub2 in Main.Elements(ns + "PassengerFare").Elements(ns + "Taxes").Elements(ns + "Tax")
where Sub2.Attribute("TaxCode").Value == "OC"
select new
{
OC = Sub2.Attributes("Amount").Sum(nd => Int32.Parse(nd.Value)),
};
値は233,218,440および173として返されます。ただし、すべての値の合計[233 + 218 + 440 + 173=1064]を返す必要があります。
さらに詳しい情報が必要な場合はお知らせください。