I have an xml fragment (doc):
<charge_details >
<charge>
<type>Maintenan ce Charge</type>
<currency>GBP </currency>
<percentage>0.3 5000</percentage>
<frequency>Mont hly</frequency>
<term>31</term>
<lower_bound>50 0000.00</lower_bound>
<upper_bound>99 9999.99</upper_bound>
</charge>
<charge>
<type>Maintenan ce Charge</type>
<currency>GBP </currency>
<percentage>0.3 5000</percentage>
<frequency>Mont hly</frequency>
<term>31</term>
<lower_bound>50 0000.00</lower_bound>
<upper_bound>99 9999.99</upper_bound>
</charge>
<charge>
<type>Quarter ly 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("m essage").Elemen ts("m_content") .Elements("cont ract").Elements ("charge_detail s").Elements("c harge")
where MMPPolicyTerms. Element("type") .Value == "Maintenanc e
Charge"
select new
{
PolicyTermType = PolicyTermType. MAINTENANCE_CHA RGE,
Percentage = (double?)MMPPol icyTerms.Elemen t("percentage ") ??
0.00,
Term = (string)MMPPoli cyTerms.Element ("term"),
UpperBound = (double?)SOMETH ING
}).FirstOrDefau lt();
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("m essage").Elemen ts("m_content") .Elements("cont ract").Elements ("charge_detail s").Elements("c harge")
where upperBound.Elem ent("type").Val ue == "Maintenanc e Charge"
select (double?)upperB ound.Element("u pper_bound") ?? 0.00)
But I don't know how to say if .Value="Mainten ance Charge" .Count() 2
Anyone know how I can do this?
<charge_details >
<charge>
<type>Maintenan ce Charge</type>
<currency>GBP </currency>
<percentage>0.3 5000</percentage>
<frequency>Mont hly</frequency>
<term>31</term>
<lower_bound>50 0000.00</lower_bound>
<upper_bound>99 9999.99</upper_bound>
</charge>
<charge>
<type>Maintenan ce Charge</type>
<currency>GBP </currency>
<percentage>0.3 5000</percentage>
<frequency>Mont hly</frequency>
<term>31</term>
<lower_bound>50 0000.00</lower_bound>
<upper_bound>99 9999.99</upper_bound>
</charge>
<charge>
<type>Quarter ly 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("m essage").Elemen ts("m_content") .Elements("cont ract").Elements ("charge_detail s").Elements("c harge")
where MMPPolicyTerms. Element("type") .Value == "Maintenanc e
Charge"
select new
{
PolicyTermType = PolicyTermType. MAINTENANCE_CHA RGE,
Percentage = (double?)MMPPol icyTerms.Elemen t("percentage ") ??
0.00,
Term = (string)MMPPoli cyTerms.Element ("term"),
UpperBound = (double?)SOMETH ING
}).FirstOrDefau lt();
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("m essage").Elemen ts("m_content") .Elements("cont ract").Elements ("charge_detail s").Elements("c harge")
where upperBound.Elem ent("type").Val ue == "Maintenanc e Charge"
select (double?)upperB ound.Element("u pper_bound") ?? 0.00)
But I don't know how to say if .Value="Mainten ance Charge" .Count() 2
Anyone know how I can do this?