1

Here I am trying to read the TID Value and I am able to read the Value(Intially it is 1)..and every time I need to increment by one and update to TID node value

 protected void Page_Load(object sender, EventArgs e)
{

    XmlDocument xml = new XmlDocument();

    xml.Load(Server.MapPath("~/XmlFile1.xml"));

    XmlNode node = xml.SelectSingleNode("AllID/ID/TID");

    int s = Convert.ToInt32( node.InnerText);

    node.InnerText= s++.ToString();

    xml.Save(Server.MapPath("~/XmlFile1.xml"));

}


But here it is not updating the TID value

<AllID>
 <ID>
<TID>1</TID>
</ID>
</AllID>
Gopal Reddy V
  • 367
  • 3
  • 9
  • Checked with small sample,, Value is updating.. Please see sample xml with your code :

    OldValue

    Select H1 node -> xml/h1.. Instead node.Value = s++.ToString();-> chnage to node.InnerText= s++.ToString();
    – Shashi Feb 21 '15 at 06:39
  • Please see below answer – Shashi Feb 21 '15 at 06:46
  • This is really duplicate of [pre vs. post increment](http://stackoverflow.com/questions/8573190/c-sharp-pre-post-increment-confusions) but since this question have nothing actually pointing to that in text I don't want to close it as duplicate.. – Alexei Levenkov Feb 21 '15 at 07:08
  • Note that none of the answers actually highlight the real problem so far... – Alexei Levenkov Feb 21 '15 at 07:09

2 Answers2

1

XmlDocument xml = new XmlDocument();

xml.Load(Server.MapPath("~/XmlFile1.xml"));

XmlNode node = xml.SelectSingleNode("AllID/ID/TID");

int s = Convert.ToInt32( node.InnerText);

 node.InnerText = (++s).ToString(); //Increment and make string

xml.Save(Server.MapPath("~/XmlFile1.xml"));
Shashi
  • 2,860
  • 2
  • 34
  • 45
0

What about node.InnerText = s++.ToString();? I haven't tested it.

Juraj Majer
  • 567
  • 5
  • 10