zoukankan      html  css  js  c++  java
  • 读取XML文件中获取特定值

            /// <summary>
            /// 获取子系统驱动获取DCM配置文件的特定值
            /// </summary>
            /// <param name="configurationFile"></param>
            /// <param name="key"></param>
            /// <returns></returns>
            public static string ReadValueByKey(ConfigurationFile configurationFile, string key)
            {
                string value = string.Empty;
                string filename = string.Empty;
                if (configurationFile.ToString() == ConfigurationFile.AppXml.ToString())
                {
                    //string exeroot = "F:\DCM\DLAX.DataCollectorMiddleware\DLAX.DataCollectorMiddleware\bin\Debug\DeviceLib\视频子系统\北京电科院\BJDKY\Start.exe";
                    string exeroot = System.Windows.Forms.Application.ExecutablePath;
                    if (exeroot.IndexOf("DeviceLib") > 0)
                    {
                        string fileroot = exeroot.Substring(0, exeroot.IndexOf("DeviceLib"));
                        filename = fileroot + "dcm.xml";
                    }

                    else
                    {
                        filename = System.AppDomain.CurrentDomain.BaseDirectory + "dcm.xml";
                    }
                        
                }

                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(filename); //加载配置文件
                }
                catch (Exception ex)
                {
                    return null;
                }
                XmlNode node = doc.SelectSingleNode("//appSettings");   //得到[appSettings]节点

                ////得到[appSettings]节点中关于Key的子节点
                XmlElement element = (XmlElement)node.SelectSingleNode("//add[@key='" + key + "']");

                if (element != null)
                {
                    value = element.GetAttribute("value");
                }

                return value;
            }

  • 相关阅读:
    checked、disabled在原生、jquery、vue下不同写法
    大白话理解闭包及相关笔试题
    reduce多种方法计算数组中某个值的出现次数
    js原生_获取url键值对
    弹窗和遮罩层的显示隐藏及空白区域关闭
    tab选项卡切换(js原生、jQuery )
    大白话理解this
    js---通过arguments来获取指定参数
    js-字符串方法
    登录linux,输入ls显示anaconda-ks.cfg cobbler.ks ....., 原因在于root@ ~ / 区别
  • 原文地址:https://www.cnblogs.com/yuesebote/p/10916469.html
Copyright © 2011-2022 走看看