I have XML in the following format that is entered either by hand or script into a text box:
<instructions>
<step index="1">Do this</step>
<step index="2">Do that</step>
</instructions>
I want to be able to click on a button to add an attribute to the instructions element so all the XML will remain intact, but the resulting XML in the text box would look like this:
<instructions iterations="3">
<step index="1">Do this</step>
<step index="2">Do that</step>
</instructions>
I was able to get the XML into an XmlDocument, but I’m having trouble adding the element and getting the results back into the text box.
Any help would be appreciated!
Here’s the code I have so far based on the feedback:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(textBoxInstructions.Text);
var attr = xmlDoc.CreateAttribute("iterations");
attr.InnerText = "3";
string strNewXML = xmlDoc.InnerXml;
textBoxInstructions.Text = strNewXML;
However, the old is the same as the new.
You can try with this code
For element