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

  • 相关阅读:
    html中label及加上属性for之后的用法
    Django中利用filter与simple_tag为前端自定义函数的实现方法
    关于自动编译iOS工程,生成app及ipa文件的方法-备
    ios打包ipa的四种实用方法(.app转.ipa)-备
    为GCD队列绑定NSObject类型上下文数据-利用__bridge_retained(transfer)转移内存管理权-备
    GCD使用经验与技巧浅谈--备
    h5与iOS的wkwebview不兼容问题
    cocoaPods 安装和应用
    .a静态库的注意事项
    UIApplication详解再解-备
  • 原文地址:https://www.cnblogs.com/yuesebote/p/10916469.html
Copyright © 2011-2022 走看看