楼主参考一下 
XmlDocument doc = new XmlDocument();
        doc.Load(Server.MapPath("data.xml"));
        StringBuilder content = new StringBuilder();
        XmlNodeList nodeLst = doc.GetElementsByTagName("movie");
        foreach (XmlNode node in nodeLst)
        {
            
            content.Append("元素名:" + node.Name + "\r\n");
            for (int i = 0; i < node.Attributes.Count; i++)
            {
                content.Append("属性名" + node.Attributes[i].Name + ":" + node.Attributes[i].Value + "\r\n");
            }
            foreach (XmlNode childNode in node.ChildNodes)
            {
                content.Append("子元素名" + childNode.Name + ":"+childNode.FirstChild.Value+"\r\n");
            }
        }
        TextBox1.Text = content.ToString();

解决方案 »

  1.   

    因为你的文档只有三层结构,我没有用遍历算法最好是采用xslt输出.
        private void test()
        {
            XmlDocument xd = new XmlDocument();
            xd.Load("e:/test.xml");        //load all movies
            XmlNodeList xnl = xd.SelectNodes("//movie");
            foreach(XmlNode xn in xnl)
            {
                //load all attributes of current movie
                foreach (XmlAttribute xa in xn.Attributes)
                {
                    Response.Write("<b>" + xa.Name + "</b>:" + xa.InnerText  + ",");
                }
                Response.Write ("<hr size=\"1\" />");            //the child nodes of current node which named movie
                foreach (XmlNode xcn in xn.ChildNodes)
                {
                    Response.Write("<b>" +xcn.Name + "</b>:" + xcn.InnerText   + "<br/>");                if (xcn.HasChildNodes)
                    {
                        Response.Write("<br/>------------------------<br/>");
                    }                //load nodes named file
                    foreach (XmlNode xccn in xcn.ChildNodes)
                    {
                        Response.Write("<b>" + xccn.Name + "</b>:" + xccn.InnerText + "<br/>");
                    }
                }
                Response.Write("<br/><br/><br/>");
            }
        }
    }
      

  2.   

    呵呵,楼上朋友非常的有礼貌,现在这样的年青人太少见了^^(貌似偶自己很老的样子-__-!!)我的理解凡foreach就是遍历,不知道有没有错.
      

  3.   

    foreach确实应该是叫遍历...是我叫错了.呵呵,我已经老了,都快27了.