update XML C#? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

update XML C#?

<CStudent> <student> <name>boy</name> <age>10</age> <location>paris</location> <phone>222-555</phone> </student> <student> <name>mark</name> <age>18</age> <location>korea</location> <phone>01012345</phone> </student> </CStudent> I want to update <name > mark </name> <phone> 01012345 </phone> To <name>jack</name> <phone> 22334455 </phone> What should i do?

13th May 2018, 3:50 PM
lee ratana
5 Answers
+ 1
Oh ,,, really good ,, I will follow this
13th May 2018, 10:06 PM
lee ratana
+ 1
Have a look at this example code https://code.sololearn.com/cFe6dBTOySBu It is really important to have the nodename correct . quote "Note, that in above code, "NodeName is actually Xpath. You can give it like Node/ChildNode/GrandChildNode and so on." Hope this helps.
14th May 2018, 9:37 PM
sneeze
sneeze - avatar
0
Have a look at this link. I like solution 3. https://www.codeproject.com/Questions/495163/Howplustopluschangeplusaplusvalueplusofpluselement XmlDocument xDoc = new XmlDocument(); xDoc.Load("YourFile.Xml"); //Then, you read like string nodeValue = xDoc .DocumentElement.SelectSingleNode("NodeName").InnerText; //You can update value like xDoc.DocumentElement.SelectSingleNode("NodeName").InnerText = newValue;
13th May 2018, 9:03 PM
sneeze
sneeze - avatar
0
//You can update value like xDoc.DocumentElement.SelectSingleNode("NodeName").InnerText = newValue; I were Update like this it was Error . //You can update value like xDoc.DocumentElement.SelectSingleNode("CStudents/student/name").InnerText = textBox.Text;
13th May 2018, 10:57 PM
lee ratana
0
Yes sir, I will try
14th May 2018, 11:03 PM
lee ratana