// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
public static void RecurseAllNodes()
{
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithNode();
    // Open a document.
    Document doc = new Document(dataDir + "Node.RecurseAllNodes.doc");

    // Invoke the recursive function that will walk the tree.
    TraverseAllNodes(doc);
}

/// <summary>
/// A simple function that will walk through all children of a specified node recursively 
/// And print the type of each node to the screen.
/// </summary>
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);
    }
}