微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XML 处理

private readonly Dictionary<string,string> datafeedConfig = new Dictionary<string,string>(); public string GetConfig(string itemName,string attributeName) { string key = itemName + "_" + attributeName; if (datafeedConfig.ContainsKey(key)) { return datafeedConfig[key]; } string configPath = AppDomain.CurrentDomain.BaseDirectory + "\\ProductdatafeedConfig\\Productdatafeed.config"; var xmlDocument = new XmlDocument(); xmlDocument.Load(configPath); XmlNode root = xmlDocument.SelectSingleNode("Productdatafeed"); if (root != null) { var selectSingleNode = root.SelectSingleNode(itemName); if (selectSingleNode != null) { if (selectSingleNode.Attributes != null) { XmlAttribute item = selectSingleNode.Attributes[attributeName]; if (item != null) { datafeedConfig.Add(key,item.Value); return item.Value; } throw new ApplicationException("未在" + configPath + "找到指定的配置项"); } } } throw new ApplicationException(configPath + "配置错误"); }

原文地址:https://www.jb51.cc/xml/300544.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。