I having a bit of trouble parsing an xml file with a namespace
XML Format
<
You can use Linq-to-XML
and Linq
itself
XDocument doc = XDocument.Load(@"file.xml");
XNamespace ns="http://rss.flightstats.com/ns/rss/1.0";
var flight = doc.Descendants(ns + "FlightHistory");
foreach (var ele in flight)
{
Console.WriteLine(ele.Attribute("FlightHistoryId").Value);
}
OR
var flight = doc.Descendants(ns + "FlightHistory")
.Select(ele => new
{
FlightHistoryId=ele.Attribute("FlightHistoryId").Value,
DepartureDate=ele.Attribute("DepartureDate").Value,
ArrivalDate=ele.Attribute("ArrivalDate").Value
}).FirstOrDefault();
if (flight != null)
{
Console.WriteLine(flight.FlightHistoryId + " " + flight.DepartureDate + " " + flight.ArrivalDate);
}