I am using xml serialization and de-serialization to read and write to an XML file. Everything is working and I love it because I can access any data from the file via the single object that I generated.
However, I have to update certain element or remove it from my xml file. From reading around the site I think I can do this with Xpath or LINQ but I still like to do it via serialization due to the above reason. Is it possible? Does serialization mean to do this kind of logic? oh and I don’t want to delete/recreate my file because it defeats the purpose of updating.
Changing it in the xml can be iffy, removing a node unless it’s one of a collection, will almost certainly break it, and possibly even then. You might be able to get this to work but it will make your code extremely fragile, and could leave you with some horrendously difficult bugs.
Deserialise it. Change the property and serialise it again.
Or don’t use serialisation to get your xml.