I have recently used linq to Xml on the application that I am using and found it really easy to use so I thought I would put together a quick how to guide:
The history to this is that we have upgraded to use Visual Studio 2008 from 2005.
The first hurdle I had was to make sure that the project was using the .Net 3.5 framework. This can be done by right clicking on the project and selecting the framework:
The second issue I had was to make sure the project had references to the required libraries:
The rest is really easy, The follow is how I read the xml document:
I noticed that the var statement had the property statement on it from the select. Which makes it easier if you have multiple properties on Xml elements i.e if the xml was:
<Sql>SELECT Name FROM Person</Sql>
So the object then should have the properties “Sql” and “Table” if they are selected.
Hope this is helpful.