欢迎访问我的博客 https://javascript.shop

遍历简单XML节点

原文发布时间为:2009-08-26 —— 来源于本人的百度文章 [由搬家工具导入]

<?xml version="1.0" encoding="gb2312" ?>
<root>
<name id="1">sdfsdf</name>
<name id="2">sdgsd</name>
<name id="3">sdf<name>

</root>

string url = Server.MapPath("../XML/zone.xml");
        System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
        xdoc.Load(url);
        System.Xml.XmlNodeList nodeList = xdoc.SelectNodes("root/name");
        foreach (System.Xml.XmlNode node in nodeList)
        {
            string strID = node.Attributes["id"].InnerText;
            if (strID=="1")
            {
                Response.Write(node.InnerXml);
            }

        }

posted @ 2017-07-13 00:12  孑孓子  阅读(106)  评论(0编辑  收藏  举报
欢迎访问我的博客 https://javascript.shop