The technical document for the Node.NextPreOrder method says "Gets next node according to the pre-order tree traversal algorithm"
What, exactly, is the "pre-order tree traversal algorithm"?
I am writing a method to delete all everything between two "bookend" bookmarks ("XXXStart" and "XXXEnd"). I'm taking the first BookmarkStart node, going up it's ParentNode tree to find the enclosing Section node and calling that "topNode", because I don't want to go outside the containing section. I then used a while loop similar to that in the example for deleting all images. But I'm finding that, in some cases, Node.NextPreorder is returning Null after deleting a few paragraphs.
Here's the code:
topNode = bkMark.ParentNode
While Not topNode Is Nothing AndAlso (topNode.NodeType <> NodeType.Body And topNode.NodeType <> NodeType.Section)
topNode = topNode.ParentNode
End While
docNode = bkMark.NextPreOrder(topNode)
While Not docNode Is Nothing
If docNode.NodeType = NodeType.BookmarkStart Then
endingBkMark = docNode
If endingBkMark.Bookmark.Name = endBkMark Then
'Then we've marked all the runs between starting bookmark and ending bookmark
Exit While
End If
End If
thisNode = docNode
docNode = docNode.NextPreOrder(topNode)
thisNode.Remove()
End While
Any hints as to why this is not working?