Creates a new empty XDocument.
new XDocument() creates an empty document.new XDocument(declaration) creates a document with an XML declaration.new XDocument(other) deep-clones an existing document.new XDocument(...content) creates a document with content nodes.new XDocument(declaration, ...content) creates a document with both.Creates a new XDocument with an XML declaration.
The XML declaration.
Creates a new XDocument with the specified content.
Root element, comments, processing instructions, or whitespace-only strings.
Creates a new XDocument with an XML declaration and content.
The XML declaration.
Root element, comments, processing instructions, or whitespace-only strings.
ReadonlydeclarationThe XML declaration for this document, or null if none was specified.
The kind of XML node this object represents.
The parent of this object in the XML tree, or null if it is a root.
Gets the first child node, or null if the container is empty.
Gets the last child node, or null if the container is empty.
Gets the next sibling node, or null if this is the last node.
Gets the previous sibling node, or null if this is the first node.
Gets the root element of this document, or null if there is none.
Appends content as children of this container.
Nodes, strings, or arrays to add.
Content rules:
Inserts the specified content immediately after this node in its parent.
One or more nodes or strings to insert.
Inserts content as the first children of this container.
Nodes, strings, or arrays to prepend.
Performs a deep structural comparison of this node with another.
The node to compare against.
true if the two nodes are structurally identical.
Compares this document with another for structural equality, including the declaration and all child nodes.
The document to compare against.
true if the documents are structurally identical.
Inserts content immediately after an existing child node.
The reference child node.
Content to insert after the child.
Inserts content immediately before an existing child node.
The reference child node.
Content to insert before the child.
Removes annotations from this object.
Removes a specific child node from this container.
The child node to remove.
Removes all child nodes from this container.
Replaces an existing child node with the specified content.
The child node to replace.
Content that replaces the child.
Replaces all child nodes with the specified content.
New content to use as children.
Serialises this document to an XML string.
The XML string representation, including the declaration if present.
Serialises this document to an indented (pretty-printed) XML string.
The indented XML string.
StaticdeepStatic convenience method for deep structural comparison of two nodes.
true if the two nodes are structurally identical.
StaticloadStaticloadStaticparse
Represents a complete XML document.
Remarks
An
XDocumentmay contain at most one XElement (the root). XAttribute and XCData are not valid document content and will throw. Non-whitespace string content will also throw.Example