From: Milo Luo Date: 2010-01-17T17:46:49+09:00 Subject: Re: How can I modify the xml file directly? David Masover wrote: > 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. Hi, David It seems that I can only truncate the original file to 0, then overwrite it directly, but it will cost a lot of IO if the file is very large. But seems that it's the best way to do that. Thank you,sir. BR, Milo -- Posted via http://www.ruby-forum.com/.