设为首页 加入收藏 网站搜索 繁體中文 中国建站网 — 站长资源分享平台

对于任意的XML的遍历

来源:网络收集 作者:佚名 时间:2007-04-26 01:31:17

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;

[1] [2]  下一页

Tags:

  • 好的评价 如果您觉得好,就请您
      0%(0)
  • 差的评价 如果您觉得差,就请您
      0%(0)
  • 相关文章
    广告赞助

    文章随便看看 设计素材 建站学院 网页模板 视频教程

    网友评论

    共有 0 位网友发表了评论,得分 0 分,平均 0 分    查看完整评论

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 1分

    内 容:

             通知管理员 验证码: