Does XmlDocument.Save saves particular changed element/attribute in file or rewrites whole xml file RRS feed

  • Question

  • After updating/adding new elements/attributes of an existing xml file using xmlDocument object of that file.

    And when say xmlDocument.Save(fileName), does it saves by rewriting whole xml file again.

    Or else just updates the changed attribute/element alone instead of storing whole file.

    I am asking this question whether, memory consumption will be high whenever xml file is read/update/write very often like every 2seconds.

    Friday, August 1, 2014 1:13 PM


All replies

    • Proposed as answer by CoolDadTx Friday, August 1, 2014 3:34 PM
    • Marked as answer by Kabila Krishnan Monday, August 4, 2014 9:05 AM
    Friday, August 1, 2014 1:17 PM
  • XmlDocument itself is a heavy weight.  The entire file is loaded into memory along with the overhead of the DOM.  For small XML files you might not notice but for MB XML files the in memory size gets large very fast.  The last time I dealt with the DOM an 80MB XML file wouldn't fit in 2GB of memory.  So if you're concerned about memory and performance then don't use XmlDocument at all.  For large XML files you'll want to look into streaming using XmlReader/XmlWriter.

    As for your original question about saving Ioana's answer is correct.  Since the file is already in memory it just blasts it out.

    Michael Taylor

    Friday, August 1, 2014 3:34 PM