如何读取XML文件内容

王朝other·作者佚名  2008-05-30
窄屏简体版  字體: |||超大  

下面是通过读取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];

}

}该程序已经过测试,没有问题。

http://www.cnblogs.com/support/archive/2006/10/21/535967.html

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航