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;
}
///
/// 获取配置
///
/// xml内容
/// 关键字
///
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;
}
}
}