What is difference between XElement and XDocument?

XElement and XDocument are the classes defined with in System.Xml.Linq namespace. XElement class represents an XML fragment. While XDocument class represents an entire XML document with all associated properties.
For Example:

XDocument doc = new XDocument(new XElement("Book",
                              new XElement("Name", ".NET Interview FAQ"),
                              new XElement("Author", "Shailendra Chauhan"))
                             );

 

Tagged , . Bookmark the permalink.

Leave a Reply