473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 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 1119

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David Veeneman | last post by:
I've been hearing a lot about LINQ in connection with Orcas, the next release of VS.NET. Micorosoft touts LINQ as the Next Big Breakthrough, but it looks to me like further muddying of application...
22
by: paululvinius | last post by:
Hi! Testing som Linq-expressions and tried to measure performance and compare it to pre-Linq programming. The folloing two methods are functional equal but the non-Linq one is twice as fast....
7
by: Andy B | last post by:
Just wondering why linq is more useful than datasets? The stuff I do doesn't seem to be too complicated to use linq with it. If I did use linq with it now, I would be doing almost the exact same...
4
by: hon123456 | last post by:
Dear all, I try to type using system.linq in Visual studio 2005. But it complains that no namespace of System.ling is found. Maybe I need to add reference to System.linq. How can I add...
9
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how...
5
by: ck1 | last post by:
Hi at all - I want to know if there are diffirence with Liqn to SQL and Linq To entity performance. I have read many article on the web that say that Linq To Entity is more fast than Linq To...
14
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
21
by: hrishy | last post by:
Hi Will LINQ be ported to Python ? regards Hrishy
1
by: hrishy | last post by:
Hi Well wouldn't it be a lot easier to query and join a xml source with a relational source with LINQ capabilites in Python. Hmm what am i missing here is there a site that takes all LINQ...
1
by: rote | last post by:
Which linq book to get me started? If there is a book C# 3.0 and linq combined i would be happy Thanks for any advices..
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.