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;
            }

  • 相关阅读:
    ubuntu重新安装mysql
    linux基本命令
    ubuntu启用root用户
    cada的常规使用
    如果有人对我的mysql的笔记感兴趣请联系我,互相学习
    10、mysql查看进程
    09、Mysql 查询是否锁表
    08、查看锁记录等待时间:
    针对发送网络附件的java方法(使用Apache的jar包调用)
    mysql的卸载重装+导入大量数据失败的解决方案+工具执行和项目执行结果不同
  • 原文地址:https://www.cnblogs.com/yuesebote/p/10898609.html
Copyright © 2011-2022 走看看