0

I'm using a XmlDocument in C# to edit my Xml file. I want to edit data like this:

<Transform>
  <Position>x</Position>
</Transform>

But i don't find a matching method yet. I try to solve this and I get something like this:

<Transform>
  <Position Positnion=x>x</Position>
</Transform>

Could You give me a method and an easy example how to do this? Thanks ;)

+++ SOLUTION +++

XmlNode formData = xmlDoc.SelectSingleNode("Transform//Position");

if (formData != null)
  {
    formData.FirstChild.Value = position.ToString();
  }
1
  • You better post your solution as an answer or mark the current answer as correct as it basically is in the solution space. Don't edit your question with the solution. Commented Nov 12, 2014 at 20:47

1 Answer 1

1

I think, help you:

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(xmlFile);

XmlNode node = xmlDoc.SelectSingleNode("Transform/Position");
node.Attributes[0].Value = newValue;

xmlDoc.Save(xmlFile);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.