Klassentest
{
privater statischer String-Stamm;
public static void showXML(string path)
{
XmlDocument xd = new XmlDocument();
xd.Load(path);
XmlNodeList xnl = xd.DocumentElement.ChildNodes;
root = xd.FirstChild.NextSibling.Name;//
Console.Write(root+"n");
foreach (XmlNode xn in xnl)
{
//Console.Write(xn.Attributes["name"].Value.ToString()+"n");
XmlNode child = xn.FirstChild;
NodeOperate(child);
}
}
public static void NodeOperate(XmlNode xn1)
{
if (xn1.HasChildNodes == true)
{
Console.Write(xn1.Name + „n“);
Console.Write("n");
XmlNode childNode = xn1.FirstChild;
NodeOperate(childNode);
}
anders
{
Console.Write(xn1.Name + „n“);
Console.Write(xn1.InnerText);
Console.Write("n");
if (xn1.NextSibling != null)
{
NodeOperate(xn1.NextSibling);
}
anders
{
int Flag = 0;
while (xn1.NextSibling == null)
{
if (xn1.Name == root)//检查是否到了根节点,如果不检查会出现节点的引用错误
{
Flag = 1;
brechen;
}
anders
{
xn1 = xn1.ParentNode;
}
}
if (Flag == 0)
{
NodeOperate(xn1.NextSibling);
}
sonst if(flag==1)
{
Console.Write("End");
}
}
}
}
}
öffentliches statisches void Main()
{
test.showXML(@"C:Dokumente und EinstellungenSKYEigene DateienVisual Studio 2005ProjekteProjekt1Projekt1system.xml");
Console.Read();
}