使用c#替换xml文档参数

Replace xml document parameters using c#

我想使用 c# 将以下 @eleval2、@eleval4 参数替换为其他一些值。net.Please 帮我完成。

<root>
<element1>
    <element2>
        @eleval2
    </element2>
</element1>
<element3>
    <element4>
        <element4>
            @eleval4
        </element4>
    </element4>
</element3>

直接更新节点:

XmlDocument xml = new XmlDocument();
xml.Load("file_name.xml"); 
xml.SelectSingleNode("/root/element1/element2").InnerText = "NewValue";

对于循环:

XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load("path_here");
    XmlNodeList tagNodes= xmlDoc.GetElementsByTagName("tag_of_your_interest");

    //Loop through first child of above list
    foreach (XmlNode chapter in tagNodes[0].ChildNodes)
    {
             //Perform your updates here 
    }

从字符串加载:

XmlDocument doc = new XmlDocument();
doc.LoadXml(str);

获取所有匹配路径的节点列表:

XmlNodeList xnList = doc.SelectNodes("/sections/notebooks/article");