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

  • 相关阅读:
    【转】Java8学习笔记(1) -- 从函数式接口说起
    解决sublime text 2总是在新窗口中打开文件(标签中打开)
    Cocoapod安装使用
    使用工具来提升Android开发效率
    Material Design之FloatingActionButton的使用
    HDU2842-Chinese Rings(递推+矩阵高速幂)
    阿里笔试题(2015)持续更新中
    Newton‘ method 的优缺点
    解决的方法:warning: Clock skew detected. Your build may be incomplete.
    云享 值得一用的在线文档即时通讯平台 新用户持续免费
  • 原文地址:https://www.cnblogs.com/yuesebote/p/10916469.html
Copyright © 2011-2022 走看看