Wednesday, 13 April 2016

XML : Edit an XML file without rewriting using XmlSerializer in C#

I have an XML file eg:

  <?xml version="1.0" encoding="utf-8"?>        <items>                     <item>          <id>1</id>          <details></details>          <description></description>        </item>         <item>          <id>2</id>          <details>          </details>          <description></description>        </item>      </items>    

Now say suppose I want to modify an XML file such that I want to add some data to details tag for item with id=2. Using XML serializer, I would have to read the whole XML file then select item with item Id 2 and modify that class object and write whole file again? So for every update I would have to read the whole xml file into memory, then edit it in memory and then re-write as a whole to the disk?

Is there any other way to achieve this? Like could I have alogic which would simply update the node to the existing XML file?

No comments:

Post a Comment