[XML-SIG] Deleting and appending of a file, without reading into memory

Andrew Kuchling akuchlin@mems-exchange.org
Thu, 3 May 2001 16:19:19 -0400


On Thu, May 03, 2001 at 07:48:34PM +0000, gary cor wrote:
>I want to add some text onto the end of an XML file just before the closing 
>tag but I don't want to read the whole file into memory as it is quite a 
>large file. I am trying to do the following:
>
>1. delete 14 characters off the end of the file (the closing tag)
  ...

This is fragile; what if there is trailing whitespace at the end of
the file?  What if the closing tag is written strangely, as '< /
closing >' or something like that?  

Now, what's the best way to do this?  You could write a simple SAX
handler where startElement() and characters() printed their input to a
file or to standard output, and then have an endElement() that outputs
a closing tag, first checking if it's the root element and inserting
the extra content.  Is there a better way?

--amk