[jdom-interest] Remove elements

Gordon Tyler gordon.tyler at sitraka.com
Tue Jun 18 15:06:42 PDT 2002

From: "Ladhani, Dilip" <dladhani at gltg.com>

> I switched to version 8 beta. However nothing seems to work.
> I tried
> iSections.remove();
> also tried
> dataRs.removeContent(elemSection)
> The underlying XML String (it's not a file) doesn't change at all. I also
am trying to use setText on an element and that doesn't work either.
> Baasically the XML string doesn't change!!!!
> Any ideas????

Removing elements doesn't change the source of the XML document that was
parsed, it only changes the in-memory JDOM object representation created
when you parsed the source. If you want to update the source with your
changes, you have to output the JDOM object representation using JDOM's
XMLOutputter class to a String.

For example:

String source = ... xml from somewhere ...
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new StringReader(source));

... do some stuff to the doc ...

XMLOutputter out = new XMLOutputter();
source = out.outputString(myDoc);


More information about the jdom-interest mailing list