Aspose.Words.Examples.CSharp.Programming_Documents.Working_with_Node.ExNode.TraverseAllNodes C# (CSharp) Method

TraverseAllNodes() public static method

A simple function that will walk through all children of a specified node recursively And print the type of each node to the screen.
public static TraverseAllNodes ( CompositeNode parentNode ) : void
parentNode CompositeNode
return void
        public static void TraverseAllNodes(CompositeNode parentNode)
        {
            // This is the most efficient way to loop through immediate children of a node.
            for (Node childNode = parentNode.FirstChild; childNode != null; childNode = childNode.NextSibling)
            {
                // Do some useful work.
                Console.WriteLine(Node.NodeTypeToString(childNode.NodeType));

                // Recurse into the node if it is a composite node.
                if (childNode.IsComposite)
                    TraverseAllNodes((CompositeNode)childNode);
            }
        }
        // ExEnd:RecurseAllNodes