使用递归函数遍历 XML [英] Traverse a XML using Recursive function
本文介绍了使用递归函数遍历 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#中使用递归函数遍历(按顺序读取所有节点)XML文档?
How can I traverse (read all the nodes in order) a XML document using recursive functions in c#?
我想要的是读取 xml(具有属性)中的所有节点并以与 xml 相同的结构打印它们(但没有节点本地名称)
What I want is to read all the nodes in xml (which has attributes) and print them in the same structure as xml (but without Node Localname)
谢谢
推荐答案
using System.Xml;
namespace ConsoleApplication1
{
class Program
{
static void Main( string[] args )
{
var doc = new XmlDocument();
// Load xml document.
TraverseNodes( doc.ChildNodes );
}
private static void TraverseNodes( XmlNodeList nodes )
{
foreach( XmlNode node in nodes )
{
// Do something with the node.
TraverseNodes( node.ChildNodes );
}
}
}
}
这篇关于使用递归函数遍历 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文