C#后台修改XML某节点值的值!

XML内容:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<object id="MessageTrigger" type="Spring.Scheduling.Quartz.SimpleTriggerObject, Spring.Scheduling.Quartz">
<property name="jobDetail" ref="MessageControlJob" />
<property name="startDelay" value="1s" />
<property name="repeatInterval" value="3600s" />
<property name="description" value="启动后1秒开始执行,每3600秒触发" />
</object>
</objects>
请问怎么修改<property name="repeatInterval" value="3600s" />中 value的值啊???

第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);本回答被提问者采纳
相似回答