XML 处理

前端之家收集整理的这篇文章主要介绍了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 + "配置错误"); }

猜你在找的XML相关文章