CompositeNodeGetChildNodes Method

Returns a live collection of child nodes that match the specified type.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public NodeCollection GetChildNodes(
	NodeType nodeType,
	bool isDeep
)

Parameters

nodeType
Type: Aspose.WordsNodeType
Specifies the type of nodes to select.
isDeep
Type: SystemBoolean
True to select from all child nodes recursively. False to select only among immediate children.

Return Value

Type: NodeCollection
A live collection of child nodes of the specified type.
Remarks

The collection of nodes returned by this method is always live.

Remarks

A live collection is always in sync with the document. For example, if you selected all sections in a document and enumerate through the collection deleting the sections, the section is removed from the collection immediately when it is removed from the document.

Examples
Demonstrates how to remove a specified TOC from a document.
// Open a document which contains a TOC
Document doc = new Document(MyDir + "Table of contents.docx");

// Remove the first TOC from the document
Field tocField = doc.Range.Fields[0];
tocField.Remove();

// Save the output
doc.Save(ArtifactsDir + "Field.RemoveTocFromDocument.docx");
Examples
Shows how to extract images from a document and save them as files.
public void ExtractImagesToFiles()
{
    Document doc = new Document(MyDir + "Images.docx");

    NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
    int imageIndex = 0;
    foreach (Shape shape in shapes.OfType<Shape>())
    {
        if (shape.HasImage)
        {
            string imageFileName =
                $"File.ExtractImagesToFiles.{imageIndex}{FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType)}";
            shape.ImageData.Save(ArtifactsDir + imageFileName);
            imageIndex++;
        }
    }
}
See Also