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