如何读取XML文件内容
下面是通过读取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];
}
}该程序已经过测试,没有问题。
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- 微软ASP.NET站点部署指南(11):部署SQL Server数据
- asp.net 六大内置对象(2)
- asp.net js模拟Button点击事件
- 谈.Net委托与线程——创建无阻塞的异步调用(一
- ASP.NET数据格式的Format--DataFormatString
- 教你如何来恢复一个丢失的数据文件
- Pro ASP.NET MVC 3 Framework学习笔记之九
- Asp.net MVC源码分析--Model Validation(Client端)实现(2)
- winform下通过webclient使用非流方式上传(post)数据和
- MVC中一个表单实现多个提交按钮(一个action搞定