Traverse a XML using Recursive function
c#, recursion, traversal, xml
Solution
using System.Xml;
namespace ConsoleApplication1
{
class Program
{
static void Main( string[] args )
{
var doc = new XmlDocument();
// Load xml document.
TraverseNodes( doc.ChildNodes );
}
private static void TraverseNodes( XmlNodeList nodes )
{
foreach( XmlNode node in nodes )
{
// Do something with the node.
TraverseNodes( node.ChildNodes );
}
}
}
}
Problem
How can I traverse (read all the nodes in order) a XML document using recursive functions in c#? What I want is to read all the nodes in xml (which has attributes) and print them in the same structure as xml (but without Node Localname) Thanks