I have never really been a fan of XML files before, sure for certain tasks they are definitely the structured format of choice, they compress well and they get through firewalls, plus they allow you to navigate “jagged” data, but the pain of having to program to them via a pretty unwieldy DOM was always in my opinion a hefty price and frankly not always worth the cost.
However all that has changed for me with .NET’s Linq to Xml, I swear I am now finding that I LOVE coding to Xml now, incredible! Hurrah the DOM is gone, the wicked witch of the west truly is dead. The new XML API as embodied by XElement (and related classes) is simply a joy to use, and the associated Linq extension methods for navigation over the document is superb.
Look at this snippet for example…
var xe = (from x in XElement.Load(spotFile).Elements("Table")
where (string)x.Attribute("Name") == txtTableName.Text
txtResults.Text = (string)xe.Element("SQL");
In this particular case the “SQL” element contains a CDATA section, but in reading the file back I can simply type cast the element to a string and the API realizes that I want the inner text and that if the inner text is in a CDATA section to simply extract it…brilliant.