[英]XML Edit data using XmlDocument in C# <> x </>
我在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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.