使用C#中的XmlDocument对数据进行XML编辑<>;x</>;
本文关键字:lt gt 编辑 XML 中的 XmlDocument 数据 使用 | 更新日期: 2023-09-27 18:30:07
我正在C#中使用XmlDocument来编辑我的Xml文件。我想编辑这样的数据:
<Transform>
<Position>x</Position>
</Transform>
但是我还没有找到匹配的方法。我试图解决这个问题,我得到了这样的东西:
<Transform>
<Position Positnion=x>x</Position>
</Transform>
你能给我一个方法和一个简单的例子吗?谢谢;)
+++解决方案+++
XmlNode formData = xmlDoc.SelectSingleNode("Transform//Position");
if (formData != null)
{
formData.FirstChild.Value = position.ToString();
}
我想,帮助你:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFile);
XmlNode node = xmlDoc.SelectSingleNode("Transform/Position");
node.Attributes[0].Value = newValue;
xmlDoc.Save(xmlFile);