zoukankan      html  css  js  c++  java
  • XML文件做数据源的读取使用

    Modelxml.xml内容

    <?xml version="1.0" encoding="utf-8"?>

    < models >

      <model id="zhangsan">

        <name>张三</ name >

        <sex>1</ sex >

        <age>24</age>

      </ model >

    </ models >

     

    读取特定对象

     private Model MessageLoad(){

    Model model=new Model();

    //CS程序

    string smtpXmlPath = string.Format(@"{0}\manager\modelxml.xml",             Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName);

    //BS程序

    string smtpXmlPath =string.Format(@"{0}\ manager\modelxml.xml", AppDomain.CurrentDomain.BaseDirectory);

     

    XmlDocument userDocument = new XmlDocument();

    userDocument.Load(EmailHelper.SmtpXmlPath);

    XmlNode senderNodeList =userDocument.SelectSingleNode("/models/model[@id=\"zhangsan\"]");

                if (senderNodeList.HasChildNodes)

                {

                  Model.Name = senderNodeList["name"].InnerText;

                  Model.Sex = senderNodeList["sex"].InnerText;

                  Model.Age = senderNodeList["age"].InnerText;

               

                }

      Return  model;

    }

    读取xml集合并绑定

    public static void BindExperimentPath(DropDownList ddlModel)

            {

                DataSet ds = new DataSet();

                objDataSet.ReadXml(string.Format(@"{0}\models\ modelxml.xml", AppDomain.CurrentDomain.BaseDirectory));

                ddlModel.DataSource = ds;

                ddlModel.DataTextField = "name";

                ddlModel.DataValueField = "age";

                ddlModel.DataBind();

       ddlModel.Items.Insert(0, new ListItem("请选择", ""));

            }

     

  • 相关阅读:
    剑指OFFER之包含min函数的栈
    剑指OFFER之二叉树的镜像
    关于【最长递增子序列(LIS)】
    题目1113:二叉树
    剑指OFFER之字符串的排列
    题目1120:全排列
    题目1460:Oil Deposit
    题目1459:Prime ring problem
    剑指OFFER之二叉树中和为某一值的路径
    python 线程、进程
  • 原文地址:https://www.cnblogs.com/Cynosure/p/2151551.html
Copyright © 2011-2022 走看看