zoukankan      html  css  js  c++  java
  • 读取XML文件

    读取指定路径下XML文件,并将读取值赋值给字典。

            /// <summary>
            /// 自定义配置文件custom.xml的节点内容集合
            /// </summary>
     public Dictionary<string, string> DicCustomText = new Dictionary<string, string>();

    public Dictionary<string, string> GetCustomConfigText(string guid)
            {
                try
                {
                    string path = Application.StartupPath;
                    string filecustom = path + "\Config\custom.xml";
                    string filetemplate = path + "\Config\template.xml";
                    string FilePath = "";
                    //如果自定义配置文件不存在,则读取模版配置文件
                    if (File.Exists(filecustom))
                    {
                        FilePath = filecustom;
                    }
                    else
                    {
                        FilePath = filetemplate;
                    }
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(FilePath);//读取指定的XML文档
                    XmlNode devicelist = xmlDoc.SelectSingleNode("DeviceList");
                    foreach (XmlNode device in devicelist.ChildNodes)
                    {
                        XmlNodeList list = device.ChildNodes;
                        foreach (XmlNode item in list)
                        {
                            if (!string.IsNullOrEmpty(guid) && device.Attributes["Guid"] != null)
                            {
                                var deviceGuid = device.Attributes["Guid"].Value;
                                if (deviceGuid == guid)
                                {
                                    DicCustomText[item.Name] = item.InnerText;
                                }
                            }
                            else
                            {
                                DicCustomText[item.Name] = item.InnerText;
                            }
                        }
                    }               
                }
                catch (Exception ex)
                {
                    log4netHelp.Error(ex.Message);
                }
                return DicCustomText;
            }

  • 相关阅读:
    yii2.0 composer安装
    php composer包管理器
    Eclipse-selenium环境搭建
    JMeter-分布式
    Jmeter-接口压力测试
    Jmeter-操作Mysql
    Jmeter参数化-关联参数
    Jmeter参数化-从文件中读取参数(CSV Data Set Config)
    Jmeter参数化-用户参数
    Jmeter-文件上传
  • 原文地址:https://www.cnblogs.com/yuesebote/p/10898609.html
Copyright © 2011-2022 走看看