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: 19.9
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.
[C#]

// Open a document which contains a TOC.
Document doc = new Document(MyDir + "Document.TableOfContents.doc");

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

// Save the output.
doc.Save(ArtifactsDir + "Document.TableOfContentsRemoveTOC.doc");
Examples
Shows how to extract images from a document and save them as files.
[C#]

public void ExtractImagesToFiles()
{
    Document doc = new Document(MyDir + "Image.SampleImages.doc");

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