CompositeNodeAppendChild Method

Adds the specified node to the end of the list of child nodes for this node.

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


public Node AppendChild(
	Node newChild


Type: Aspose.WordsNode
The node to add.

Return Value

Type: Node
The node added.


If the newChild is already in the tree, it is first removed.

If the node being inserted was created from another document, you should use ImportNode(Node, Boolean, ImportFormatMode) to import the node to the current document. The imported node can then be inserted into the current document.


Shows how to construct an Aspose Words document node by node.
Document doc = new Document();

// A newly created blank document still comes one section, one body and one paragraph
// Calling this method will remove all those nodes to completely empty the document

// This document now has no composite nodes that content can be added to
// If we wish to edit it, we will need to repopulate its node collection,
// which we will start to do with by creating a new Section node
Section section = new Section(doc);

// Append the section to the document

// Lets set some properties for the section
section.PageSetup.SectionStart = SectionStart.NewPage;
section.PageSetup.PaperSize = PaperSize.Letter;

// The section that we created is empty, lets populate it. The section needs at least the Body node
Body body = new Body(doc);

// The body needs to have at least one paragraph
// Note that the paragraph has not yet been added to the document, 
// but we have to specify the parent document
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information
Paragraph para = new Paragraph(doc);

// We can set some formatting for the paragraph
para.ParagraphFormat.StyleName = "Heading 1";
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;

// So far we have one empty paragraph in the document
// The document is valid and can be saved, but lets add some text before saving
// Create a new run of text and add it to our paragraph
Run run = new Run(doc);
run.Text = "Hello World!";
run.Font.Color = Color.Red;

Assert.AreEqual("Hello World!" + ControlChar.SectionBreakChar, doc.GetText());

doc.Save(ArtifactsDir + "Section.CreateFromScratch.docx");

See Also