对于任意的XML的遍历
来源:互联网 发布时间:2008-09-05 17:11:00
class test
{
private static string root;
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);
}
else
{
Console.Write(xn1.Name + "\n");
Console.Write(xn1.InnerText);
Console.Write("\n");
if (xn1.NextSibling != null)
{
NodeOperate(xn1.NextSibling);
}
else
{
int flag = 0;
while (xn1.NextSibling == null)
{
if (xn1.Name == root)//检查是否到了根节点,如果不检查会出现节点的引用错误
{
flag = 1;
break;
}
else
{
xn1 = xn1.ParentNode;
}
}
if (flag == 0)
{
NodeOperate(xn1.NextSibling);
}
else if(flag==1)
{
Console.Write("End");
}
}
}
}
}
public static void Main()
{
test.showXML(@"C:\Documents and Settings\SKY\My Documents\Visual Studio 2005\Projects\Project1\Project1\system.xml");
Console.Read();
}
猜你喜欢
- !DOCTYPE--------------------------------------------------------------
- 引言 性能是一个特征。您必须预先设计性能,否则您以后就得重写应用程序。就是说,有哪些好的策略可使 Active Server Pages (
- 前言Matplotlib的可以把很多张图画到一个显示界面,在作对比分析的时候非常有用。对应的有plt的subplot和figure的add_
- 在计算机和信息技术领域里 I/O 这个术语表示输入 / 输出 ( 英语:Input / Output ) ,通常指数据在存储器(内部和外部)
- 总有人认为linux搭建php环境很复杂,然后尝试安装lnmp一键安装包。其实说白了就是安装一个web服务器,然后支持php即可,很简单的,
- Broadcast广播是numpy对不同形状(shape)的数组进行数值计算的方式,对数组的算术运算通常在相应的元素上进行。如果两个数组a和
- 本文实例为大家分享了vue实现简单全选和反选的具体代码,供大家参考,具体内容如下<!DOCTYPE html><html
- 创建主键可以有两种方式:create table 表名(字段名 类型,字段名 类型,……primary key(name));或者是crea
- 01. 装饰器语法糖如果你接触 Python 有一段时间了的话,想必你对 @ 符号一定不陌生了,没错 @ 符号就是装饰器的语法糖。它放在一个
- javascript的字符集:javascript程序是使用Unicode字符集编写的。Unicode是ASCII和Latin-1的超集,并
- 以下代码实现环境是mac系统,本地配置mysql服务端和navicat premium客户端,python环境是配置了pymysql的ana
- 本文为大家分享了路由嵌套的SPA实现的步骤:A(/a)组件需要嵌套B组件(/b)和C组件(/c)①准备嵌套其它组价的父组件 指定一个容器在A
- 阅读上一篇:Freshow工具使用方法一. eval加密是在网马解密中最常见的,eval在jscript脚本中实际上是一个函数,简单可以理解
- 这个需求是有个表结构,本身设计为 但现在需要将blob里地17、18、19三个字段里的数据作为数字保存在blob外新增的三个字段Gem1 G
- 题目描述给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它
- 在进行数据抓取时,经常会遇到IP被限制的情况,常见的解决方案是搭建 * 池,或购买IP代理的服务。除此之外,还有一个另外的方法就是使用家里
- react-native安装流程1.npx react-native init AwesomeProject报错运行 cd ./demo/i
- 本文将梳理github上最火的wechat_jump_game的实现思路,并解析其图像处理部分源码首先废话少说先看效果 核心思想获取棋子到下
- MJML是一种现代的电子邮件工具,使开发人员可以在所有设备和邮件客户端上创建美观、响应迅速的出色电子邮件。这种标记语言是为了减少编写响应式电
- 一道Python面试题的几种解答: 两个元祖T1=('a', 'b'), T2=('c',