XDocument Constructor (Object)
Initializes a new instance of the XDocument class with the specified content.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
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.
The following example creates a document, and then adds a comment and an element to it. It then composes another document using the results of a query.
This example produces the following output:
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.