3
Answers

c# - winform - how to update particular xml node

Memento

Memento

12y
3.6k
1
My xml file:
<?xml version="1.0" standalone="yes"?>
<Food>
   <Fruit>
        <name>apple</name>
        <color>red</color>
        <taste>sweet</taste>
        <price>4</price>
   </Fruit>
</Food>

I load this file into forms controls - without problems, but if i change the value of some controls and want to update particular xml node - nothing happens. For example, i want to change the price of apple, according to my TextBox1.Text:

file01 = new XmlDocument();
file01.Load(filePath);
XmlElement root = file01.DocumentElement;
XmlNodeList nodes = root.SelectNodes("/Food/Fruit");
foreach (XmlNode node in nodes)
{
if (node["name"].InnerText == "apple")
{
node["price"].InnerText = textBox1.Text;}}

I also tried TextBox1.Text convert to string - also nothing happend. XML file remains unchanged.
Any suggestion, pls. How to finish ?

Answers (3)
Next Recommended Forum