Skip to content

Update values in xml

Sairam Soham

Asked Apr 30, 2015, 4:49 PM EDT1 answer
Share
LinkedInX

In the attached xml file I need to update the value of each and every price tag by existing value+5000.


and then save this updated xml file with the same name.

Will it be possible to do this in C#?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi, my suggestions is Serialize/Deserialize object. Then You can easily edit XML text (Insert, Update, Delete etc).


    Serialize example:
    Java
        string sFileName = "XmlDoc";
        Object YourObject = new Object();
        System.Xml.Serialization.XmlSerializer ser = null;
        using (FileStream fs = new FileStream(sFileName, FileMode.Create))
        {
             ser.Serialize(fs, YourObject);
        }

    Deserialize example:
    Code
        using (FileStream fs = new FileStream(sFileName, FileMode.Open, FileAccess.Read))
        {
             o = serializer.Deserialize(fs);
        }
    0