I have been using XElement class a lot lately, I was doing some performance tests on this to figure out the difference between this and XmlDocument class and here is what I found.
First of all XElement class is part of .NET Framework 3.5, it was introduced with XML to Linq and is part of System.Xml.Linq namespace. This class has been totally written from scratch to get better usability with LINQ. XElement.Nodes and XElement.Attribtues return IEnumerable which could be easily used to traverse nodes. You can also use them Lambda expressions. For more information on XML to LINQ check http://msdn.microsoft.com/en-us/library/bb387098.aspx.
In my case, I have created a test bench (console application) with two static methods, one uses XMLDocument and the other uses XElement to generate XML. The test case is very simple, iterate through the System assembly exported type, construct a giant XML and save it to a stream. Here is the code for both of the static methods.
If you look at the above code, the XElement code is small and uses LINQ expressions for generating XML. By using the following code, I repeatedly test the amount of time it takes for each method to execute.
From the above code, you can see that I am testing each method for 50 times. Additionally, after each test, I explicitly call Garbage Collector to clean up objects created by two methods. Now Here is the screen shot of the output.
You can see very clearly, the huge difference in the time it takes to create XML. The difference seems to vary from 6x to 10x times. Specially, this is very important in ASP.NET applications and Web Services where every millisecond counts. One more thing to note that XElement is part of System.Xml.Linq.dll which is part of .NET Framework 3.5, but still uses .NET 2.0 CLR, thus technically you can use a local copy of System.Xml.Linq.dll within your application in cases where you are missing .NET 3.5. But, you will loose all goodness of updations and service packs by the .NET team.