The query
should hold the list of ice-creams, and their details. It should be of the type
IEnumerable
.
// Simple Query
IEnumerable IcrmList =
from c in Icecreams.Elements()
select new IcecreamList(
(string)c.Element("Flavor"),
(string)c.Element("ServingSize"),
(double)c.Element("Price"),
(string)c.Element("Nutrition")
);
We retrieve details of ice-creams from the IcrmList variable, which is of type
IEnumerable, and display that in a rich text box, which is added
in the form. This code will give a list of ice-creams with details such as Flavour,
ServingSize, Price, and Nutrition.
foreach (IcecreamList p in IcrmList)
Console.WriteLine(p.flavor + ":" + p.servingSize +
":" + p.price + ":" + p.nutrition + "\n");
If we don't have values for any element in the XML, how do we handle it? For
example, in the previous XML data, the Nutrition value is missing and whenever
the Nutrition value is empty we should display null in that. In this case, the query
would be as follows:
XElement Icecreams2 = new XElement("Icecreams2",
from c in Icecreams.
Pages:
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114