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

  • 相关阅读:
    Android用Gson解析JSON字符串
    使用PullToRefresh实现下拉刷新和上拉加载
    Android应用框架-Volley网络通信框架
    Android基本架构
    HWOJ-字符串的逆序
    剑指offer-第七章面试案例2(树中两个节点的公共祖先节点)
    剑指offer-第七章面试案例1(字符串转换为整型)
    剑指offer-第六章面试中的各项能力(不用加减乘除做加法)
    剑指offer-第六章面试中的各项能力(圆圈中剩下的最后数字)
    以《淘宝网》为例,描绘质量属性的六个常见属性场景
  • 原文地址:https://www.cnblogs.com/yuesebote/p/10916469.html
Copyright © 2011-2022 走看看