CompositeNodeGetChild Method

Returns an Nth child node that matches the specified type.

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

Syntax

public Node GetChild(
	NodeType nodeType,
	int index,
	bool isDeep
)

Parameters

nodeType
Type: Aspose.WordsNodeType
Specifies the type of the child node.
index
Type: SystemInt32
Zero based index of the child node to select. Negative indexes are also allowed and indicate access from the end, that is -1 means the last node.
isDeep
Type: SystemBoolean
True to select from all child nodes recursively. False to select only among immediate children. See remarks for more info.

Return Value

Type: Node
The child node that matches the criteria or null if no matching node is found.

Remarks

If index is out of range, a null is returned.

Remarks

Note that markup nodes (StructuredDocumentTag and SmartTag) are traversed even when isDeep = false and GetChild is invoked for non-markup node type. For example if the first run in a para is wrapped in a StructuredDocumentTag, it will still be returned by GetChild(NodeType.Run, 0, false).

Examples

Shows how to enumerate immediate children of a CompositeNode using the enumerator provided by the ChildNodes collection.
Document doc = new Document();

Paragraph paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);
paragraph.AppendChild(new Run(doc, "Hello world!"));
paragraph.AppendChild(new Run(doc, " Hello again!"));

NodeCollection children = paragraph.ChildNodes;

// Paragraph may contain children of various types such as runs, shapes and so on
foreach (Node child in children)
    if (child.NodeType.Equals(NodeType.Run))
    {
        Run run = (Run)child;
        Console.WriteLine(run.Text);
    }
Shows how to expand the formatting from styles onto the rows and cells of the table as direct formatting.
Document doc = new Document(MyDir + "Tables.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

// First print the color of the cell shading. This should be empty as the current shading
// is stored in the table style
double cellShadingBefore = table.FirstRow.RowFormat.Height;
Console.WriteLine("Cell shading before style expansion: " + cellShadingBefore);

// Expand table style formatting to direct formatting
doc.ExpandTableStylesToDirectFormatting();

// Now print the cell shading after expanding table styles. A blue background pattern color
// should have been applied from the table style
double cellShadingAfter = table.FirstRow.RowFormat.Height;
Console.WriteLine("Cell shading after style expansion: " + cellShadingAfter);

doc.Save(ArtifactsDir + "Document.TableStyleToDirectFormatting.docx");

See Also