Vehicle gas DTD .NET objects and XML parsing with LINQ

  • June 10, 2010
  • James Skemp
The code contained below is a rough draft, and will eventually be moved into an assembly, and the code posted. At some point in 2007 I started keeping track of my gas mileage in an XML file, with a custom DTD for validation (and intellisense in oXygen). I present below the code necessary to create an rough object from the XML, and the LINQ to parse it out. C# objects public class Vehicle { public int Id { get; set; } public String Make { get; set; } public String Model { get; set; } public int Year { get; set; } public IEnumerable Fillups { get; set; } } public class Fillup { public int Id { get; set; } public DateTime Date { get; set; } public int MilesTotal { get; set; } public Decimal MilesDriven { get; set; } public Decimal Gallons { get; set; } public Decimal CostPerGallon { get; set; } public Decimal CostTotal { get; set; } public String Notes { get; set; } }</code></pre> LINQ to XML XDocument vehicleGasXml = XDocument.

Read More