tags:

views:

928

answers:

2

as stated above, whats the difference between XElemen.load and XDocument.load? they both load xml files...

+4  A: 

The difference is that an XElement type represents an XML fragment while the XDocument type represents an entire XML document with all associated meta-data.

That being said however, for most simple cases you can use them interchangeably.

It is important to understand the subtle differences in querying between these two types and for more information on that I would recommend that you please read Querying an XDocument vs. Querying an XElement:

When you load a document via XDocument.Load, you will notice that you have to write queries slightly differently than when you load via XElement.Load.

Andrew Hare
so performance-wise they're both the same
Ayyash
Also, XDocument is suggested if you are going to send the generated XML through the web to some webservice. But you asked for `.Load`, so this is not probably your case.
Alex Bagnolini
+2  A: 

There are not many scenarios that require you to create an XDocument. Instead, you can usually create your XML trees with an XElement root node. Unless you have a specific requirement to create a document (for example, because you have to create processing instructions and comments at the top level, or you have to support document types), it is often more convenient to use XElement as your root node.

Straight from Valid Content of XElement and XDocument Objects. As far as the Load methods...they both load content into their respective objects.

Justin Niessner