// Collection of code snippets by Arne Vajhøj
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now)
using System;
using System.Xml;
namespace E
{
public class MainClass
{
private const string INDENT = " ";
private static string GenerateMenu(XmlNode node, string indent)
{
string htmlMenu = "";
if(node.HasChildNodes && node.FirstChild.NodeType != XmlNodeType.Text)
{
if(indent.Length > 0)
{
htmlMenu += (indent + "
\n");
}
if(node.Attributes.Count > 0)
{
htmlMenu += (indent + node.Attributes[0].Value + "\n");
}
htmlMenu += (indent + "\n");
foreach(XmlNode newnode in node.ChildNodes)
{
htmlMenu += GenerateMenu(newnode, indent + INDENT);
}
htmlMenu += (indent + "
\n");
if(indent.Length > 0)
{
htmlMenu += (indent + "\n");
}
}
else
{
htmlMenu += (indent + "" + node.InnerText + "\n");
}
return htmlMenu;
}
public static void Main(string[] args)
{
XmlDocument menuXML = new XmlDocument();
menuXML.Load(@"c:\test.xml");
Console.WriteLine(GenerateMenu(menuXML.DocumentElement, ""));
}
}
}