22
schangxiang@126.com
2025-08-23 cea8c2b4129aead2c796153738690b00366c3bb6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Xml;
 
namespace iWareWebservice.AppUtil
{
    public class XmlHelper
    {
        public static string GetNodeValue(string xmlFile, string elementsName, string attributeName, string attributeValue)
        {
            string conStr = "";
            string xmlFilePath = @System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + xmlFile;
            XmlDocument doc = new XmlDocument();
            doc.Load(xmlFilePath);
            XmlNodeList appSettingNodes = doc.GetElementsByTagName(elementsName);
 
            foreach (XmlNode node in appSettingNodes)
            {
                XmlElement att = (XmlElement)node;
                if (att.GetAttribute("name").Equals(attributeName))
                {
                    conStr = att.GetAttribute(attributeValue);
                    break;
                }
            }
            return conStr;
        }
 
        /// <summary>
        /// 获取配置
        /// </summary>
        /// <param name="xmlFileContent">xml内容</param>
        /// <param name="paramKey">关键字</param>
        /// <returns></returns>
        public static string GetSppSettingsKeyValue(string xmlFileContent,string xmlFile, string paramKey)
        {
            string keyStr = "";
 
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlFileContent);
            XmlNodeList appSettingNodes = doc.GetElementsByTagName("add");
 
            foreach (XmlNode node in appSettingNodes)
            {
                XmlElement att = (XmlElement)node;
                if (att.GetAttribute("key").Equals(paramKey))
                {
                    keyStr = att.GetAttribute("value");
                    break;
                }
            }
            return keyStr;
        }
    }
}