the XML file that i have:
<NameList>
<personDetail>
<first_name>Rock</first_name>
<last_name>Shajahan</last_name>
<age>24</age>
</personDetail>
</NameList>
In the main :
XDocument doc = XDocument.Load(@"nameList.xml");
var node = doc.Descendants("personDetail").FirstOrDefault(personDetail => personDetail.Element("first_name").Value == this.textBox1.Text);
node.SetElementValue("first_name", this.textBox1.Text);
node.SetElementValue("last_name", this.textBox2.Text);
node.SetElementValue("age", this.textBox3.Text);
Console.WriteLine(node);
doc.Save(@"nameList.xml");
I don't have red id variable, when I update by node.SetElementValue("age", this.textBox3.Text); to change other variable (e.g. last_name) there are all works fine. But if i wanna change the "root" which "first_name", it will shows "An unhandled exception of type 'System.NullReferenceException' occurred".