+ 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?
5 Réponses
+ 1
Oh ,,, really good ,, I will follow this
+ 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.
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;
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;
0
Yes sir, I will try