栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 前沿技术 > 人工智能 > NLP

对于任意的XML的遍历

NLP 更新时间:发布时间: 百科书网 趣学号
对于任意的XML的遍历

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 SettingsSKYMy documentsVisual Studio 2005ProjectsProject1Project1system.xml");            Console.Read();        }

以上就是对于任意的XML的遍历的内容,更多相关内容请关注PHP中文网(www.iotsi.net)!

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/794766.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号