<item day="2010-06-01" theprice="600" inprice="550" backprice="50" breakfast="1" isfull="0" /> 
  <item day="2010-06-02" theprice="600" /> 
  <item day="2010-06-03" theprice="600"  /> 
  <item day="2010-06-04" theprice="600"  /> 
  <item day="2010-06-05" theprice="600"  /> 
  <item day="2010-06-06" theprice="600" /> 
  <item day="2010-06-07" theprice="600" /> 
  <item day="2010-06-08" theprice="600"  /> 
  <item day="2010-06-09" theprice="600"  /> 
  <item day="2010-06-10" theprice="600"  /> 
 取如某一天:
 XmlNode node = xml.DocumentElement.SelectSingleNode("//item[@day= '2010-06-01']");如何按日期范围取如2010-06-05 至 2010-06-08 之间的记录
语句如何写

解决方案 »

  1.   

    XmlNodeList nodes = xml.DocumentElement.SelectNodes("/item[@day]");
    foreach (XmlNode node in nodes)
    {
      XmlNode attrNode = node.Attributes.GetNamedItem("day");
      string attr = attrNode.Value.ToString();
      DateTime dt = DateTime.Parse(attr);
      if (dt.CompareTo(DateTime.Parse("2010-06-05")) >= 0&&dt.CompareTo(DateTime.Parse("2010-06-08")) <= 0)
      {
         //Do Work...
      }
    }测试通过