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("请选择", ""));

            }

     

  • 相关阅读:
    python 协程之Greenlet
    python 协程
    python 多进程通信之Manger
    python 多线程通信之Queue
    python 多进程
    python threading之queue
    python threading之同步条件(Event)
    python threading之条件变量同步(condition)
    python之字符串常用方法
    python之字典操作
  • 原文地址:https://www.cnblogs.com/Cynosure/p/2151551.html
Copyright © 2011-2022 走看看