zoukankan      html  css  js  c++  java
  • C#读取XML配置文件

    DataSource.xml文件,要放在bin/debug/目录下:

     1 <?xml version="1.0" encoding="utf-8" ?>
     2 <DataSource>
     3   <type>
     4     <ID>001</ID>
     5     <name>张三</name>
     6   </type>
     7   <type>
     8     <ID>002</ID>
     9     <name>李四</name>
    10   </type>
    11   <type>
    12     <ID>003</ID>
    13     <name>王五</name>
    14   </type>
    15 </DataSource>

    CS代码:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Windows.Forms;
     9 
    10 namespace 超市收银Demo
    11 {
    12     public partial class Main : Form
    13     {
    14         public Main()
    15         {
    16             InitializeComponent();
    17         }
    18 
    19         private void button_loadXML_Click(object sender, EventArgs e)
    20         {
    21             this.listBox1.Items.Clear();
    22             DataSet set = new DataSet();
    23             set.ReadXml(Application.StartupPath + "\DataSource.xml");
    24             foreach (DataRowView view in set.Tables[0].DefaultView)
    25             {
    26                 this.listBox1.Items.Add(view["ID"].ToString() + "   " + view["name"].ToString());
    27             }
    28             this.listBox1.SelectedIndex = 0;
    29         }
    30 
    31         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    32         {
    33             string value = this.listBox1.SelectedItem.ToString();
    34             this.textBox1.Text = value;
    35         }
    36     }
    37 }

    运行结果:

  • 相关阅读:
    erlang遍历目录
    C/C++ makefile自动生成工具(comake2,autotools,linux),希望能为开源做点微薄的贡献!
    shell 文件操作
    互联网分享知识(一)
    分页查询,你真的懂吗?
    awk神器
    Unicode编码解码在线转换工具
    awk 留底
    软件开发真的这么简单吗?
    php性能优化
  • 原文地址:https://www.cnblogs.com/lavalike/p/3669150.html
Copyright © 2011-2022 走看看