From: David Masover Date: 2010-01-17T04:26:31+09:00 Subject: Re: How can I modify the xml file directly? On Saturday 16 January 2010 11:50:04 am Seebs wrote: > On 2010-01-16, Milo Luo wrote: > > I meant without string or tmp file, write to original file. > > In general, on most systems, the only modifications you can make without > a temporary file or something comparable are those which do not change the > number of characters in a file. You can't insert or delete characters in > the middle of a file. Not true; you can append to the end of a file. But yes, that's the point, and that's why XML (or JSON, or Yaml) is not efficient as a database format, unless you work around it somehow. It's fine (preferred, even) if the files are small enough, but yes, you are going to have to write to a tempfile first, then move that on top of the original file. Or, if you're feeling reckless, you can truncate the original file to 0, then overwrite it directly.