CompositeNodeGetText Method

Gets the text of this node and of all its children.

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


public override string GetText()

Return Value

Type: String


The returned string includes all control and special characters as described in ControlChar.


Shows the difference between calling the GetText and ToString methods on a node.
Document doc = new Document();

// Enter a field into the document
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField("MERGEFIELD Field");

// GetText will retrieve all field codes and special characters
Assert.AreEqual("\u0013MERGEFIELD Field\u0014«Field»\u0015\u000c", doc.GetText());

// ToString will give us the plaintext version of the document in the save format we put into the parameter
Assert.AreEqual("«Field»\r\n", doc.ToString(SaveFormat.Text));
Shows how to output all paragraphs in a document that are bulleted or numbered.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Numbered list item 1");
builder.Writeln("Numbered list item 2");
builder.Writeln("Numbered list item 3");

builder.Writeln("Bulleted list item 1");
builder.Writeln("Bulleted list item 2");
builder.Writeln("Bulleted list item 3");

NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph para in paras.OfType<Paragraph>().Where(p => p.ListFormat.IsListItem))
    Console.WriteLine($"This paragraph belongs to list ID# {para.ListFormat.List.ListId}, number style \"{para.ListFormat.ListLevel.NumberStyle}\"");

See Also