下面是通過讀取XML文件中的內容並顯示在textbox的例子:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.XML;
using System.XML.XPath;
public partial class _Default : System.Web.UI.Page
{
public string[] x = new string[4];
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XMLDocument();
xmlDoc.Load(Server.MapPath("table.xml"));//你的XML文件
XmlNodeList xmlList = XMLDoc.SelectSingleNode("MapSheet").ChildNodes;
foreach (XmlNode xmlNo in XMLList)
{
//XmlNodeList xe = (XmlNodeList)XMLNo;
XmlElement xe = (XmlElement)XMLNo;
{
if (xe.Name == "TableName")
{
y[0] = xe.InnerText;
}
if (xe.Name == "DataSource")
{
y[1] = xe.InnerText;
}
if (xe.Name == "UserName")
{
y[2] = xe.InnerText;
}
if (xe.Name == "PassWord")
{
y[3] = xe.InnerText;
}
}
}
TextBox1.Text=y[0];
TextBox2.Text = y[1];
TextBox3.Text = y[2];
TextBox4.Text = y[3];
}
}該程序已經過測試,沒有問題。