[jdom-interest] Inserting elements to an XML file without rewriting the entire file

Jason Hunter jhunter at servlets.com
Sat Jun 14 00:53:16 PDT 2003


>  From a JavaWorld article I picked up this:
> 
> "JDOM also provides a full document view with random access but, 
> surprisingly, it does not require the entire document to be in memory"

Isn't that article about 3 years old?  The JDOM model is such that it 
can support partial documents, and initially we planned on working on an 
impl of that, but in the time since it's not been a high priority at 
all.  You can build partial docs (see the ElementScanner in 
jdom-contrib) but we don't do lazy construction as originally designed.

> I am trying to figure out how to use JDOM to insert elements in an XML 
> file.  So far, what I am doing it reading the file through a SAXBuilder, 
> modifying the document and writting to the file using the XMLOutputter. 
>  However, this seems to write the entire document to the file replacing 
> all its contents every time.

That's pretty much the way JDOM and most XML libs work naturally.  You 
could output just an element or list of elements, and do an insert 
directly into the file if you'd prefer.  But you have to know what 
you're doing.  It's sad XML doesn't make appending easy.

-jh-




More information about the jdom-interest mailing list