C#后台修改XML某节点值的值!
XML内容:<?xmlversion="1.0"encoding="utf-8"?><objectsxmlns="http://www.springframework.n...
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的值啊??? 展开
<?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的值啊??? 展开
展开全部
/// <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);
}
/// 保存配置
/// </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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/// <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);
}
/// 修改结点值
/// </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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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);
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);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询