CompositeNodeGetChild Method

Returns an Nth child node that matches the specified type.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
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 extract a specific child node from a CompositeNode by using the GetChild method and passing the NodeType and index.
Paragraph paragraph = (Paragraph) doc.GetChild(NodeType.Paragraph, 0, true);
Examples
Shows how to test if a node is inside a field by using an XPath expression.
// Let's pick a document we know has some fields in
Document doc = new Document(MyDir + "Mail merge destination - Northwind employees.docx");

// Let's say we want to check if the Run below is inside a field
Run run = (Run) doc.GetChild(NodeType.Run, 5, true);

// Evaluate the XPath expression. The resulting NodeList will contain all nodes found inside a field a field (between FieldStart 
// and FieldEnd exclusive). There can however be FieldStart and FieldEnd nodes in the list if there are nested fields 
// in the path. Currently does not find rare fields in which the FieldCode or FieldResult spans across multiple paragraphs
NodeList resultList =
    doc.SelectNodes("//FieldStart/following-sibling::node()[following-sibling::FieldEnd]");

// Check if the specified run is one of the nodes that are inside the field
foreach (Node node in resultList)
{
    if (node == run)
    {
        Console.WriteLine("The node is found inside a field");
        break;
    }
}
See Also