这是我的XML源。它还有更多内容。
<Cproducts>
<ID>001</ID>
<Name>name one</Name>
<Availability>
<Departure>
<Date>2015-12-03T00:00:00.0000000+00:00</Date>
<Pricing>
<Price>
<Type>ADT</Type>
<Value>175.00</Value>
<Qty>20</Qty>
</Price>
<Price>
<Type>CHD</Type>
<Value>95.00</Value>
<Qty>5</Qty>
</Price>
<Price>
<Type>INF</Type>
<Value>0.00</Value>
<Qty>5</Qty>
</Price>
<Price>
<Type>FAM</Type>
<Value>0.00</Value>
<Qty>0</Qty>
</Price>
<Price>
<Type>SEN</Type>
<Value>175.00</Value>
<Qty>20</Qty>
</Price>
</Pricing>
</Departure>
<Departure>
<Date>2015-12-06T00:00:00.0000000+00:00</Date>
<Pricing>
<Price>
<Type>ADT</Type>
<Value>175.00</Value>
<Qty>20</Qty>
</Price>
<Price>
<Type>CHD</Type>
<Value>95.00</Value>
<Qty>5</Qty>
</Price>
<Price>
<Type>INF</Type>
<Value>0.00</Value>
<Qty>5</Qty>
</Price>
<Price>
<Type>FAM</Type>
<Value>0.00</Value>
<Qty>0</Qty>
</Price>
<Price>
<Type>SEN</Type>
<Value>175.00</Value>
<Qty>20</Qty>
</Price>
</Pricing>
</Departure>
<Availability>
</Cproducts>
在我的情况下,我希望能够遍历所有可用的日期。也就是说,当用户从表单中选择一个日期时,根据该日期提供其他数据。为了实现这一点,我必须查看所有可用的日期。我应该如何做呢?
以下是我在MVC中的代码:
public void getDatas(string destination, string cruisetype, string datetime)
{
XElement rootele = XElement.Load(Server.MapPath("~/XmlFiles/CruiseData/cruiseprodutstwo.xml"));
var selecttoDate = rootele.Elements("Cproducts").Elements("Availability").Elements("Departure").Elements("Date"); //here I want to get the data that the [date == datetime]
var getneededData = rootele.Elements("CruiseProduct") .Where(l => l.Element("Location").Value == destination );
使用此方法,我们可以在整个文档中检查并获取 Location 等于给定字符串的数据。我想要通过整个日期进行搜索。@Uwe Keim 先生,能否帮助我解决这个问题。 - user5541842