I am getting the flight details from the expedia API, please check the link below for the XML format.
The result output contains Rateinfo then flight details as separate node and there is no relation between rateinfo and flightsegment.
Normally I load the XML into dataset and use the dataset to populate the records, but in this case there is no relation between rate and flight segment, how will I parse this XML in C#. I need to show the user the flight segments and the corresponding rates.
http://api.ean.com/ean-services/rs/air/200919/xmlinterface.jsp?cid=55505&resType=air&intfc=ws&apiKey=fc9hjrvrur9vr4y2dqa249w4&xml=<AirSessionRequest method="getAirAvailability"><AirAvailabilityQuery><originCityCode>MCI</originCityCode><destinationCityCode>CLT</destinationCityCode><departureDateTime>09/01/2011 01:00 AM</departureDateTime><returnDateTime>09/04/2011 01:00 AM</returnDateTime><fareClass>Y</fareClass><tripType>R</tripType><Passengers><adultPassengers>2</adultPassengers></Passengers><xmlResultFormat>1</xmlResultFormat><searchType>2</searchType></AirAvailabilityQuery></AirSessionRequest>
A dataset represents relational data much easier than hierarchial data, which is what the xml represents, and that is probably the crux of your problem.
Linq2Xml is one option, or you could create a set of classes that are seriealizable and deserialize the xml into instances of the class, so then you can just iterate through the classes with foreach, or use linq on them.
I’m not saying this is the best way to go about doing what you need, but it is relatively tidy, and you don’t need to deal with xml, just class instances. I tested this with the xml you provided and it worked quite well, although I do think that the Linq2Xml method might be more performant – Not 100% sure though.
Assuming your xml is in a variable called sXmlResult: