Memento

Memento

  • NA
  • 111
  • 133.5k

c# - winform - how to update particular xml node

Apr 15 2012 12:55 PM
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)