用户登陆|用户注册|建站服务|广告合作
您现在的位置: 首页 >> 建站实务 >> 网络编程 >> .Net篇 >> 正文
站内搜索:
如何读取XML文件内容
[作者:佚名|来源:互联网|时间:2006-10-23| 收藏 投稿 ]【
 

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


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


Tags:
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
快速注册通道
赛酷网·中国西部第一建站门户
关于我们 | 投稿指南 | 广告服务 | 建站服务 | 联系我们 | 网站地图 | 友情连接 | 诚征英才
地址:中国·昆明盘龙区丽水天锦A栋15楼A06 服务热线:0871-5610002 5732371联系我55693344 联系我80796509
建站交流群:17577271 下载交流群:11885804 22003060 35468519 交流论坛
© CopyRight 2005-2007, Syku.Net, Inc. All Rights Reserved
赛酷网络版权所有 滇ICP备05000398号