I’m trying to add strings from an XML file to a textbox, but with no success yet.What i want to do is go through the “date” elements, and if “bejovo” has a match with “date”element, then put the element “name” value in a List, and sum the price.Here is my code.
if (File.Exists(path))
{
XDocument doc = XDocument.Load(path);
var c = from x in doc.Descendants("order")
where x.Element("date").Value == bejovo
select new
{
//??
};
foreach (var item in c)
{
textBox1.Text = item.ToString();
}
}
And here is my XML file:
<user id="0">
<order id="0">
<date>2012.11.20. 1:29:20</date>
<menuelem db="0">
<name>Pizza</name>
<price>1290</price>
</menuelem>
<menuelem db="1">
<name>Coke</name>
<price>300</price>
</menuelem>
</order>
</user>
<user id="0">
<order id="1">
<date>2012.11.19. 21:49:29</date>
<menuelem db="0">
<name>Milk</name>
<price>200</price>
</menuelem>
</order>
</user>
So in case bejovo=”2012.11.20. 1:29:20″,then my result must be “Pizza” and “Coke” and the price is 1590.
Surely this code has no validation:
The output goes like:
Pizza, Coke price:1590