Update xml programmatically with C #

I am trying to upgrade xml without linq (I am using VC 2.0). My xml file format:


<schedule>
<id>0</id>
<name>yusuf</name>
<status>0</status>
</schedule>

AFTER UPDATE:

<schedule>
<id>0</id>
<name>yusuf</name>
<status>1</status>
</schedule>

but i don't know what update status = 0 to status = 1

+3
source share
2 answers

You can do this using System.Xml.XmlDocumentin any version of .NET (except Silverlight, where it exists only XDocument):

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xml); // or doc.Load(path)
    doc.SelectSingleNode("/schedule/status").InnerText = "1";
    string newXml = doc.OuterXml; // or doc.Save(path);
+13
source

Fill in your XML in the XmlDocument, perform the update and save the result.

+2
source

Source: https://habr.com/ru/post/1702625/


All Articles