I'm pretty new to using LINQ so I'm not entirely sure of all the correct syntaxes etc.
Here's what I've got so far
My XML
<?xml version="1.0"?>
<Bookings>
<Booking BookingNumber="300067649">
<FLIGHTS>
<FlightGroups>
<FlightGroup ID="1 ">
<Flights>
<Flight ID="1">
<ADULTS>1</ADULTS>
<DEPARTURE_DATE>18/02/2006</DEPARTURE_DATE>
</Flight>
</Flights>
</FlightGroup>
</FlightGroups>
</FLIGHTS>
</Booking>
</Bookings>
I get this from a web service controlled by an outside company so i'm unable to change the syntax
Here's the LINQ i'm using in my .Net code
Dim root As XElement = XElement.Load(New StringReader(xmlstring))
Dim tests As IEnumerable(Of XElement) = From el In
root.Elements("Booking").Elements("FLIGHTS").Descendants()
Where CType(el.Element("DEPARTURE_DATE"), DateTime).Date <= DateTime.Now.Date
For Each el As XElement In tests
Response.Write(el)
Next
The string xmlstring being the XML from above.
The problem is that this is giving me an error which is:
Value cannot be null.
Parameter name: element
Basically i'm trying to select all flights that are before todays date and just can't seem to get this to work.
Any help would be appreciated