OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Appending to an XML document

[ Lists Home | Date Index | Thread Index ]
  • From: Ross Bleakney <rossb@wrq.com>
  • To: "'xml-dev@ic.ac.uk'" <xml-dev@ic.ac.uk>
  • Date: Tue, 7 Dec 1999 15:08:31 -0800

My apologies if you have already read this in the XSL list. I (and
apparently several other people) have a need to append an element onto an
existing XML file. I would like to avoid reading in the whole document and
then writing it back out again. My original plan was to open the file, find
the end of it, back up a bit to find the last tag, write the new element and
then rewrite the closing tag. I am looking for a generic solution.

I know of no XML API that allows for modifying a document. They make it easy
to create new documents out of old ones, but they don't allow you to modify
an existing file. Doing so would mean the possibility of optimization that
would greatly reduce disk I/O. For example, if you had XML like this:

<Events>
   <Event>...<Event>
   <Event>...<Event>
</Events>

It would be really nice to write code like this:

	ModifyXML modXML = new ModifyXML("MyDoc.XML");	
	Element event = modXML.createElement("Event");
	event.appendChild(modXML.createTextNode("A big event happened"));
	modXML.appendChild("Events", event);
	modXML.update();

An implementor of this interface could take advantage of the fact that
<Events> is the main tag and perform the same sort of work I suggested
(backing up from the end and then writing). The routines for this interface
would be very limited since this would only be used when you want to modify
a document and you know that using SAX (or DOM) is inefficient. Thus there
would be no reason to have an "insertBefore". The API could be limited to
appending and deleting. 

Is there something like this already?

Thanks,
Ross

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo@ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS