第1个回答 推荐于2018-04-05
/// <summary>
/// 保存配置
/// </summary>
/// <param name="strTarget">节点名</param>
/// <param name="strValue">新值</param>
/// <param name="strSource">路径</param>
public static void SaveXmlConfig(string strTarget, string strValue, string strSource)
{
string xmlPath = HttpContext.Current.Server.MapPath(strSource);
System.Xml.XmlDocument xdoc = new XmlDocument();
xdoc.Load(xmlPath);
XmlElement root = xdoc.DocumentElement;
XmlNodeList elemList = root.GetElementsByTagName(strTarget);
elemList[0].InnerXml = strValue;
xdoc.Save(xmlPath);
}
第2个回答 2013-09-04
/// <summary>
/// 修改结点值
/// </summary>
/// <param name="xmlNode">节点</param>
/// <param name="AttributeName">属性名称</param>
/// <param name="Value">值</param>
public void SetValue(XmlNode xmlNode, string AttributeName, string Value)
{
XmlAttribute xmlAttr = xmlNode.Attributes[AttributeName];
if (xmlAttr == null)
{
xmlAttr = xmlNode.OwnerDocument.CreateAttribute(AttributeName);
}
xmlAttr.Value = Value;
xmlNode.Attributes.Append(xmlAttr);
}
第3个回答 推荐于2016-06-02
var xml=new XmlDocument();
xml.Load(String Path);
var _node= xml..DocumentElement.GetElementsByTagName("property")
..OfType<XmlNode>().First(node=>node..Attributes["name"]=="repeatInterval");
_node.Attributes["value"].InnerXml="You Word";
xml.Sava(String Path);本回答被提问者采纳