NodeClone Method

Creates a duplicate of the node.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.11.0

ExpandedSyntax

public Node Clone(
	bool isCloneChildren
)

Parameters

isCloneChildren
Type: SystemBoolean
True to recursively clone the subtree under the specified node; false to clone only the node itself.

Return Value

Type: Node
The cloned node.

ExpandedRemarks

This method serves as a copy constructor for nodes. The cloned node has no parent, but belongs to the same document as the original node.

This method always performs a deep copy of the node. The isCloneChildren parameter specifies whether to perform copy all child nodes as well.

ExpandedExamples

Shows how to clone composite nodes with and without their child nodes.
Document doc = new Document();
Paragraph para = doc.FirstSection.Body.FirstParagraph;
para.AppendChild(new Run(doc, "Hello world!"));

// Clone the paragraph and the child nodes
Node cloneWithChildren = para.Clone(true);

Assert.IsTrue(((CompositeNode)cloneWithChildren).HasChildNodes);
Assert.AreEqual("Hello world!", cloneWithChildren.GetText().Trim());

// Clone the paragraph without its child nodes
Node cloneWithoutChildren = para.Clone(false);

Assert.IsFalse(((CompositeNode)cloneWithoutChildren).HasChildNodes);
Assert.AreEqual(string.Empty, cloneWithoutChildren.GetText().Trim());

ExpandedSee Also