views:

67

answers:

1

Hi,

i am using a large xml file having in the following format:

<Sales>
  <Sale>
    <Date>04/20/2010</Date>
    <Time>18:17:29</Time>
    <Id>P00000001</Id>
    <Name>Prod Name</Name>
    <Description>Prod Desc</Description>
    <Category>Prod Category</Category>
    <Subcategory>Prod Subcategory</Subcategory>
    <Size>Prod Size</Size>
    <Price>25</Price>
    <Image>image path</Image>
  </Sale>
<Sales>

my goal is to display to sum the prices and count items sold for a period of time:

    XDocument xmlDoc = XDocument.Load("Data.xml");

        DateTime date = new DateTime();
        var queryWeek = from sale in xmlDoc.Descendants("Sale")
                        where ((sale.Element("Date")>= date.Date.AddDays(-7)) && ((sale.Element("Date")<= date.Date())))
                        select sale.Element("Price");

       Console.WriteLine("",queryWeek);

debugger complains: Error 1 Operator '>=' cannot be applied to operands of type

'System.Xml.Linq.XElement' and 'System.DateTime'

Error 2 Non-invocable member 'System.DateTime.Date' cannot be used like a method. 

help please devin

A: 

You are attempting to compare a DateTime and the XElement. You need to change the XElement to a DateTime for comparison: DateTime.Parse(sale.Element("Date").Value) >= date.Date.AddDays(-7).

Yuriy Faktorovich