我有一个xml文件,想用C#代码更新并保存目标负载的值。我的代码如下,正在尝试将XML显示如下-
var fileName = textBox1.Text;
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load(fileName);
xmlDoc.SelectSingleNode("factoryTest/targetLoad").InnerText = "80";
xmlDoc.Save(fileName);
<?xml version="1.0" encoding="utf-8"?>
<factoryTest xmlns="urn:gcpm">
<targetLoad>90</targetLoad>
<isAccepted>true</isAccepted>
<isCertified>true</isCertified>
<isAtRatingConditions>true</isAtRatingConditions>
<supervisorName>Eric Larson</supervisorName>
</factoryTest>
答案 0 :(得分:0)
我已经解决了这个问题。
XDocument xdoc = XDocument.Load(tFileName);
xdoc.Elements("{urn:gcpm}factoryTest").Elements("{urn:gcpm}targetLoad").FirstOrDefault().Value = textBox2.Text;
xdoc.Save(tFileName);