EDN Admin
Well-known member
hey gurus. normally I would submit code to show where I got stuck, but Im having a lockup of the brain and just dont know where to start on this one.
Im getting comfortable with the LINQ queries but this one is baffling me.
I would like to query the xml file below with the following filter
<span style="font-size:small <span style="font-size:small
<pre class="prettyprint lang-vb Dim query =
From el In doc.Descendants("RECIPE")
Where el.Element("NAME").Value = "MAMAS PIE"[/code]
<br/>
from there I would like to return the sum of the (quantity) * (sweetness) for each apple.
for example (4*2)+(3*1)+(4*2)=19<span style="font-size:small
<pre class="prettyprint <?xml version="1.0" encoding="utf-8"?>
<RECIPES>
<RECIPE>
<NAME>MAMAS PIE</NAME>
<STYLE>OLD FASHIONED</STYLE>
<CHEF>MAMA</CHEF>
<DATE>10</DATE>
<INGREDIENTS>
<APPLES>
<APPLE>
<NAME>Gala</NAME>
<QUANTITY>2</QUANTITY>
<COLOR>pink</COLOR>
<SWEETNESS>4</SWEETNESS>
</APPLE>
<APPLE>
<NAME>MACINTOSH</NAME>
<QUANTITY>3</QUANTITY>
<COLOR>RED</COLOR>
<SWEETNESS>1</SWEETNESS>
</APPLE>
<APPLE>
<NAME>GOLDEN DELICIOUS</NAME>
<QUANTITY>4</QUANTITY>
<COLOR>GOLD</COLOR>
<SWEETNESS>2</SWEETNESS>
</APPLE>
</APPLES>
<SUGARS>
<SUGAR>
<NAME>TRUCKLE</NAME>
<COLOR>BROWN</COLOR>
<PRICE>2.25</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE>
<RECIPE>
<NAME>DADS PIE</NAME>
<STYLE>NEW AGE</STYLE>
<CHEF>DAD</CHEF>
<DATE>15</DATE>
<INGREDIENTS>
<APPLES>
<APPLE>
<NAME>GALA</NAME>
<COLOR>PINK</COLOR>
<SWEETNESS>3</SWEETNESS>
</APPLE>
<APPLE>
<NAME>GRANNY SMITH</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>4</SWEETNESS>
</APPLE>
<APPLE>
<NAME>Golden Delicious</NAME>
<SWEETNESS>4</SWEETNESS>
<COLOR>gold</COLOR>
</APPLE>
</APPLES>
<SUGARS>
<SUGAR>
<NAME>CANE</NAME>
<COLOR>WHITE</COLOR>
<PRICE>1.5</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE>
<RECIPE>
<NAME>PETES PIE</NAME>
<STYLE>OLD FASHIONED</STYLE>
<CHEF>MAMA</CHEF>
<DATE>12</DATE>
<INGREDIENTS>
<APPLES>
<APPLE>
<NAME>MACINTOSH</NAME>
<COLOR>RED</COLOR>
<SWEETNESS>1</SWEETNESS>
</APPLE>
<APPLE>
<NAME>GOLDEN DELICIOUS</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>2</SWEETNESS>
</APPLE>
</APPLES>
<SUGARS>
<SUGAR>
<NAME>TRUCKLE</NAME>
<COLOR>BROWN</COLOR>
<PRICE>2.25</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE>
</RECIPES>[/code]
absolutely stuck
THanks
View the full article
Im getting comfortable with the LINQ queries but this one is baffling me.
I would like to query the xml file below with the following filter
<span style="font-size:small <span style="font-size:small
<pre class="prettyprint lang-vb Dim query =
From el In doc.Descendants("RECIPE")
Where el.Element("NAME").Value = "MAMAS PIE"[/code]
<br/>
from there I would like to return the sum of the (quantity) * (sweetness) for each apple.
for example (4*2)+(3*1)+(4*2)=19<span style="font-size:small
<pre class="prettyprint <?xml version="1.0" encoding="utf-8"?>
<RECIPES>
<RECIPE>
<NAME>MAMAS PIE</NAME>
<STYLE>OLD FASHIONED</STYLE>
<CHEF>MAMA</CHEF>
<DATE>10</DATE>
<INGREDIENTS>
<APPLES>
<APPLE>
<NAME>Gala</NAME>
<QUANTITY>2</QUANTITY>
<COLOR>pink</COLOR>
<SWEETNESS>4</SWEETNESS>
</APPLE>
<APPLE>
<NAME>MACINTOSH</NAME>
<QUANTITY>3</QUANTITY>
<COLOR>RED</COLOR>
<SWEETNESS>1</SWEETNESS>
</APPLE>
<APPLE>
<NAME>GOLDEN DELICIOUS</NAME>
<QUANTITY>4</QUANTITY>
<COLOR>GOLD</COLOR>
<SWEETNESS>2</SWEETNESS>
</APPLE>
</APPLES>
<SUGARS>
<SUGAR>
<NAME>TRUCKLE</NAME>
<COLOR>BROWN</COLOR>
<PRICE>2.25</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE>
<RECIPE>
<NAME>DADS PIE</NAME>
<STYLE>NEW AGE</STYLE>
<CHEF>DAD</CHEF>
<DATE>15</DATE>
<INGREDIENTS>
<APPLES>
<APPLE>
<NAME>GALA</NAME>
<COLOR>PINK</COLOR>
<SWEETNESS>3</SWEETNESS>
</APPLE>
<APPLE>
<NAME>GRANNY SMITH</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>4</SWEETNESS>
</APPLE>
<APPLE>
<NAME>Golden Delicious</NAME>
<SWEETNESS>4</SWEETNESS>
<COLOR>gold</COLOR>
</APPLE>
</APPLES>
<SUGARS>
<SUGAR>
<NAME>CANE</NAME>
<COLOR>WHITE</COLOR>
<PRICE>1.5</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE>
<RECIPE>
<NAME>PETES PIE</NAME>
<STYLE>OLD FASHIONED</STYLE>
<CHEF>MAMA</CHEF>
<DATE>12</DATE>
<INGREDIENTS>
<APPLES>
<APPLE>
<NAME>MACINTOSH</NAME>
<COLOR>RED</COLOR>
<SWEETNESS>1</SWEETNESS>
</APPLE>
<APPLE>
<NAME>GOLDEN DELICIOUS</NAME>
<COLOR>GOLD</COLOR>
<SWEETNESS>2</SWEETNESS>
</APPLE>
</APPLES>
<SUGARS>
<SUGAR>
<NAME>TRUCKLE</NAME>
<COLOR>BROWN</COLOR>
<PRICE>2.25</PRICE>
</SUGAR>
</SUGARS>
</INGREDIENTS>
</RECIPE>
</RECIPES>[/code]
absolutely stuck
THanks
View the full article