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

Mike Olson Mike.Olson@fourthought.com
Thu, 03 May 2001 14:31:10 -0600


Andrew Kuchling wrote:
> 
> 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?

If the doc is that big, what about breaking it into smaller docs and
using XInclude?

Then to add a new section, load the "hub" document (which will be pretty
small now) and add a new include tag.  Then write the new content to the
referenced file.

Mike


> 
> --amk
> 
> _______________________________________________
> XML-SIG maillist  -  XML-SIG@python.org
> http://mail.python.org/mailman/listinfo/xml-sig

-- 
Mike Olson				 Principal Consultant
mike.olson@fourthought.com               (303)583-9900 x 102
Fourthought, Inc.                         http://Fourthought.com 
Software-engineering, knowledge-management, XML, CORBA, Linux, Python