递归遍历xml

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__);
}
}
}
}

 

 

 

 

  

posted @ 2014-05-28 17:31  本杰明·喝茶  阅读(320)  评论(0编辑  收藏  举报