首页 > 代码库 > 遍历简单XML节点

遍历简单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);
            }

        }

遍历简单XML节点