日期:2014-05-18  浏览次数:20927 次

C#winFrom如何将信息导出XML文件格式
例如打开一个界面后怎样将里面的数据信息导出为XML文件保存起来,如何在导入就可以把文件里的数据加进来就可以了,有没有简单的例子呢谢谢各位了
数据格式是一个树型4级菜单
-aaaa
  -2323
    -3333
      4444
希望导入以后的格式也和上面一样




------解决方案--------------------

给你发个读的。写的你就应该会了吧。
XmlTextReader reader = new XmlTextReader( "C:\\test.xml ");
reader.Read();

while (reader.Read())
{
reader.MoveToElement();
Console.WriteLine( "XmlTextReader Properties Test ");
Console.WriteLine( "=================== ");

// Read this properties of element and display them on console
Console.WriteLine( "Name: " + reader.Name);
Console.WriteLine( "Base URI: " + reader.BaseURI);
Console.WriteLine( "Local Name: " + reader.LocalName);
Console.WriteLine( "Attribute Count: " + reader.AttributeCount.ToString());
Console.WriteLine( "Depth: " + reader.Depth.ToString());
Console.WriteLine( "Line Number: " + reader.LineNumber.ToString());
Console.WriteLine( "Node Type: " + reader.NodeType.ToString());
Console.WriteLine( "Attribute Count: " + reader.Value.ToString());
}