您的位置:首页 > 其它

递归遍历xml

2014-05-28 17:31 127 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace ConsoleApplication1
{
internal class Program
{
private static void Main(string[] args)
{
List<string> list = new List<string>();
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load(@"E:\Downloads\E-InvoiceSample.xml");

XmlNodeList xnl = xmlDoc.DocumentElement.ChildNodes;
readxml(xnl, list);
Console.ReadLine();
}

public static void readxml(XmlNodeList xmlnl, List<string> list__)
{
foreach (XmlNode xl in xmlnl)
{
if (xl.ChildNodes.Count == 0)
{
list__.Add(xl.Value);
if (xl.Value == " ") xl.Value = "Null";
Console.WriteLine(xl.Value);

}
else
{
readxml(xl.ChildNodes, list__);
}
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: