I have an xml fragment (doc):
<charge_details>
<charge>
<type>Maintenance Charge</type>
<currency>GBP</currency>
<percentage>0.35000</percentage>
<frequency>Monthly</frequency>
<term>31</term>
<lower_bound>500000.00</lower_bound>
<upper_bound>999999.99</upper_bound>
</charge>
<charge>
<type>Maintenance Charge</type>
<currency>GBP</currency>
<percentage>0.35000</percentage>
<frequency>Monthly</frequency>
<term>31</term>
<lower_bound>500000.00</lower_bound>
<upper_bound>999999.99</upper_bound>
</charge>
<charge>
<type>Quarterly Admin Charge</type>
<currency>GBP</currency>
<percentage>22.00000</percentage>
<frequency />
</charge>
<charge>
<type>Dealing Settlement Charge</type>
<currency>GBP</currency>
<charge_amount>22.00</charge_amount>
<frequency />
</charge>
</charge_details>
and I need to do the following:
var policyTerms = (from MMPPolicyTerms in
doc.Elements("message").Elements("m_content").Elem ents("contract").Elements("charge_details").Elemen ts("charge")
where MMPPolicyTerms.Element("type").Value == "Maintenance
Charge"
select new
{
PolicyTermType = PolicyTermType.MAINTENANCE_CHARGE,
Percentage = (double?)MMPPolicyTerms.Element("percentage") ??
0.00,
Term = (string)MMPPolicyTerms.Element("term"),
UpperBound = (double?)SOMETHING
}).FirstOrDefault();
I need to only select UpperBound when the Maintenance Charge node occurs
twice (as in the xml fragment above). In that case, I need to select the
second instance upper_bound value into UpperBound
I'm not sure how to do the nested UpperBound select
I've tried
UpperBound =(from upperBound in
doc.Elements("message").Elements("m_content").Elem ents("contract").Elements("charge_details").Elemen ts("charge")
where upperBound.Element("type").Value == "Maintenance Charge"
select (double?)upperBound.Element("upper_bound") ?? 0.00)
But I don't know how to say if .Value="Maintenance Charge" .Count() 2
Anyone know how I can do this?