This came up as a requirement in one of our projects. The objective of this is to put all node names in an excel file. The example I have uses a recursive function to output all node names.

csharp Code:
  1. using System;
  2. using System.Xml;
  3.  
  4. namespace StripMe
  5. {
  6.     class Class1
  7.     {
  8.         public static int GetNodeTypeCount(XmlNode node, XmlNodeType nodeType)
  9.         {
  10.             // Recursively loop through the given node and return
  11.             // the number of occurences of a specific nodeType.
  12.             int i = 0;
  13.  
  14.             if (node.NodeType == nodeType)
  15.                 i = i + 1;
  16.  
  17.             if (node.HasChildNodes)
  18.                 foreach (XmlNode cNode in node.ChildNodes)
  19.                 {
  20.                     i = i + GetNodeTypeCount(cNode, nodeType);
  21.                     if (cNode.NodeType == XmlNodeType.Element)
  22.                         Console.WriteLine(cNode.Name);
  23.                 }  
  24.             return i;
  25.         }
  26.  
  27.         [STAThread]
  28.         static void Main(string[] args)
  29.         {
  30.             try
  31.             {
  32.                 XmlDocument doc = new XmlDocument();
  33.                 doc.Load(args[0]);
  34.                 XmlNodeList nodeList = doc.GetElementsByTagName("*");
  35.                 Class1.GetNodeTypeCount(doc.DocumentElement, XmlNodeType.Element);
  36.                 Console.ReadLine();
  37.             }
  38.             catch (XmlException xmlEx)        // Handle the XML Exceptions here.        
  39.             {
  40.                 Console.WriteLine("{0}", xmlEx.Message);
  41.             }
  42.             catch (Exception ex)              // Handle the Generic Exceptions here.
  43.             {
  44.                 Console.WriteLine("{0}", ex.Message);
  45.             }
  46.         }
  47.     }
  48. }
Code:
The way to use this is pass the file name that you want to parse as the first parameter.
For e.g -
c:\>TraverseXML Quote.XML