//创建XmlReader实例
using (XmlReader xr = XmlReader.Create(Server.MapPath("info.xml"))) { while (xr.Read()) { //根据节点类型输出内容 switch (xr.NodeType) { case XmlNodeType.Element://节点开始符号及其属性 Response.Write(Server.HtmlEncode("<" + xr.Name)); while (xr.MoveToNextAttribute()) { Response.Write(" " + xr.Name + "=" + xr.Value); } Response.Write(Server.HtmlEncode(">")); break; case XmlNodeType.Text://文本内容 Response.Write(xr.Value); break; case XmlNodeType.EndElement://结束符号 Response.Write(Server.HtmlEncode("</" + xr.Name + ">")); break; } } }