NodePreviousPreOrder Method

Gets the previous node according to the pre-order tree traversal algorithm.

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

Syntax

public Node PreviousPreOrder(
	Node rootNode
)

Parameters

rootNode
Type: Aspose.WordsNode
The top node (limit) of traversal.

Return Value

Type: Node
Previous node in pre-order order. Null if reached the rootNode.

Examples

Shows how to delete all images from a document using pre-order tree traversal.
Document doc = new Document(MyDir + "Images.docx");
Assert.AreEqual(10, doc.GetChildNodes(NodeType.Shape, true).Count);

Node curNode = doc;
while (curNode != null)
{
    Node nextNode = curNode.NextPreOrder(doc);

    if (curNode.PreviousPreOrder(doc) != null && nextNode != null)
        Assert.AreEqual(curNode, nextNode.PreviousPreOrder(doc));

    // Several shape types can have an image including image shapes and OLE objects
    if (curNode.NodeType == NodeType.Shape && ((Shape)curNode).HasImage)
        curNode.Remove();

    curNode = nextNode;
}

// The only remaining shape doesn't have an image
Assert.AreEqual(1, doc.GetChildNodes(NodeType.Shape, true).Count);
Assert.False(((Shape)doc.GetChild(NodeType.Shape, 0, true)).HasImage);

See Also