Difference between XElement and XDocument

 Posted by Ddd on 2/14/2011 | Category: LINQ Interview questions | Views: 10391 | Points: 40
Answer:

Both are the classes defined by System.Xml.Linq namespace

XElement class
represents an XML fragment
XDocument class represents an entire XML document with all associated meta-data.

example:

XDocument d = new XDocument(
new XComment("hello"),
new XElement("book",
new XElement("bookname", "ASP.NET"),
new XElement("authorname", "techmedia"),

)
);


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response