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: 21.2.0

ExpandedSyntax

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.

ExpandedExamples

Shows how to traverse the document's node tree using the pre-order traversal algorithm, and delete any encountered shape with an image.
Document doc = new Document(MyDir + "Images.docx");

Assert.AreEqual(9, 
    doc.GetChildNodes(NodeType.Shape, true).OfType<Shape>().Count(s => s.HasImage));

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

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

    if (curNode.NodeType == NodeType.Shape && ((Shape)curNode).HasImage)
        curNode.Remove();

    curNode = nextNode;
}

Assert.AreEqual(0,
    doc.GetChildNodes(NodeType.Shape, true).OfType<Shape>().Count(s => s.HasImage));

ExpandedSee Also