空网页
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
namespace xxx{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("XMLFile.xml"));
XmlNodeList nodeList;
XmlNode root = doc.DocumentElement;
nodeList = root.SelectNodes("//Students");
Response.Write("读取的XML内容:" + "<br>");
foreach (XmlNode xmlNode in nodeList)
{
XmlNodeList list = xmlNode.ChildNodes;
foreach (XmlNode xmlNode1 in list)
{
Response.Write(xmlNode1.InnerText);
Response.Write(" ");
}
Response.Write("<br>");
}
}
}
}
xml文件内容:
<?xml version="1.0" encoding="utf-8" ?>
<DocumentElement>
<Students>
<ID>1</ID>
<NAME>张琴</NAME>
<Phone>13918678629</Phone>
<Address>朝阳门外大街</Address>
<City>北京</City>
</Students>
<Students>
<ID>2</ID>
<NAME>邵飞</NAME>
<Phone>13698562314</Phone>
<Address>海淀区清河镇</Address>
<City>北京</City>
</Students>
<Students>
<ID>3</ID>
<NAME>王宁</NAME>
<Phone>15896322589</Phone>
<Address>徐家汇美罗城</Address>
<City>上海</City>
</Students>
</DocumentElement>
执行效果: