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 root element of this document, or null if there is none.
Gets the previous sibling node, or null if this is the first node.
Gets the next sibling node, or null if this is the last node.
Returns a shallow copy of this container's child nodes.
A new array containing all direct child XNode instances.
Inserts content immediately after an existing child node.
The reference child node.
Content to insert after the child.
Appends content as children of this container.
Nodes, strings, or arrays to add.
Content rules:
Replaces all child nodes with the specified content.
New content to use as children.
Removes all child nodes from this container.
Returns all descendant nodes of this container in document order.
A flat array of all descendant XNode instances.
Inserts content as the first children of this container.
Nodes, strings, or arrays to prepend.
Inserts content immediately before an existing child node.
The reference child node.
Content to insert before the child.
Replaces an existing child node with the specified content.
The child node to replace.
Content that replaces the child.
Removes a specific child node from this container.
The child node to remove.
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.
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.
StaticparseStaticloadStaticloadInserts the specified content immediately after this node in its parent.
One or more nodes or strings to insert.
Returns all sibling nodes that precede this node.
An array of XNode instances before this node.
Returns all sibling nodes that follow this node.
An array of XNode instances after this node.
Performs a deep structural comparison of this node with another.
The node to compare against.
true if the two nodes are structurally identical.
StaticdeepStatic convenience method for deep structural comparison of two nodes.
First node.
Second node.
true if the two nodes are structurally identical.
Removes annotations from this object.
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