前端之家收集整理的这篇文章主要介绍了
XML 处理,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
private readonly Dictionary<string,string> data
FeedConfig = new Dictionary<string,string>(); public string GetConfig(string itemName,string attributeName) { string key = itemName + "_" + attributeName; if (data
FeedConfig.ContainsKey(key)) { return data
FeedConfig[key]; } string configPath = AppDomain.CurrentDomain.BaseDirectory + "\\ProductData
FeedConfig\\ProductData
Feed.config"; var xmlDocument = new XmlDocument(); xmlDocument.Load(configPath); XmlNode root = xmlDocument.SelectSingleNode("ProductData
Feed"); if (root != null) { var selectSingleNode = root.SelectSingleNode(itemName); if (selectSingleNode != null) { if (selectSingleNode.Attributes != null) { XmlAttribute item = selectSingleNode.Attributes[attributeName]; if (item != null) { data
FeedConfig.Add(key,item.Value); return item.Value; } throw new ApplicationException("未在" + configPath + "找到指定的配置项"); } } } throw new ApplicationException(configPath + "配置
错误"); }
原文链接:https://www.f2er.com/xml/300544.html