471,354 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

How do you do this in LINQ to XML

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?
Apr 7 '08 #1
0 1061

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David Veeneman | last post: by
22 posts views Thread by paululvinius | last post: by
7 posts views Thread by Andy B | last post: by
4 posts views Thread by hon123456 | last post: by
9 posts views Thread by =?Utf-8?B?cmF1bGF2aQ==?= | last post: by
5 posts views Thread by ck1 | last post: by
14 posts views Thread by thj | last post: by
21 posts views Thread by hrishy | last post: by
1 post views Thread by hrishy | last post: by
1 post views Thread by rote | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.