• 大小: 50KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-28
  • 语言: C#
  • 标签: C#  

资源简介

C#读取XML配置文件 C#读取XML配置文件C#读取XML配置文件C#读取XML配置文件C#读取XML配置文件

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.xml;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            string[] szServerAdress = new string[100];

            ReadConfig(“config.xml“ szServerAdress);
        }

        private void ReadConfig(string sConfigPath string[] szServerAdress)
        {
            xmlDocument xmlConfig = new xmlDocument();
            try
            {
                xmlConfig.Load(sConfigPath);
            }
            catch
            {

                throw;
            }
            xmlNodeList xmlHostList;
            xmlHostList = xmlConfig.GetElementsByTagName(“host“);
            int i = 0;
            foreach (xmlElement host in xmlHostList)

            {

                szServerAdress[i++] = host.Attributes[“ip“].Value;
                Console.WriteLine(host.Attributes[“ip“].Value);

            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     47616  2018-02-08 15:28  WindowsFormsApplication2\.vs\WindowsFormsApplication2\v14\.suo

     文件        189  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\App.config

     文件       2916  2018-02-08 15:29  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\config.xml

     文件       9216  2018-02-08 15:34  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe

     文件        189  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe.config

     文件      22016  2018-02-08 15:34  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.pdb

     文件      22696  2018-02-08 15:35  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe

     文件        189  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe.config

     文件        490  2017-03-19 05:00  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe.manifest

     文件       2916  2018-02-08 15:31  WindowsFormsApplication2\WindowsFormsApplication2\config.xml

     文件       1303  2018-02-08 15:34  WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs

     文件       2044  2018-02-08 15:29  WindowsFormsApplication2\WindowsFormsApplication2\Form1.Designer.cs

     文件       5817  2018-02-08 15:29  WindowsFormsApplication2\WindowsFormsApplication2\Form1.resx

     文件       1464  2018-02-08 15:29  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7463  2018-02-08 15:29  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       1356  2018-02-08 15:35  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.FileListAbsolute.txt

     文件        976  2018-02-08 15:30  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.GenerateResource.Cache

     文件       2384  2018-02-08 15:30  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csprojResolveAssemblyReference.cache

     文件       9216  2018-02-08 15:34  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.exe

     文件        180  2018-02-08 15:30  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Form1.resources

     文件      22016  2018-02-08 15:34  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.pdb

     文件        180  2018-02-08 15:30  WindowsFormsApplication2\WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Properties.Resources.resources

     文件        536  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\Program.cs

     文件       1356  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\Properties\AssemblyInfo.cs

     文件       2861  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\Properties\Resources.Designer.cs

     文件       5612  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\Properties\Resources.resx

     文件       1111  2018-02-08 15:28  WindowsFormsApplication2\WindowsFormsApplication2\Properties\Settings.Designer.cs

............此处省略17个文件信息

评论

共有 条评论