SV: [jdom-interest] Merging JDOM documents

Per Norrman pernorrman at
Tue Oct 7 08:15:10 PDT 2003


what did you expect when you detached the root
element from the document? 

You must either clone the element


or, if concurrency is not an issue, save a reference
to the detached element and after finishing
the process, detach it from the first document and set
it back as root element in the second.

   Per Norrman

> -----Ursprungligt meddelande-----
> Från: jdom-interest-admin at 
> [mailto:jdom-interest-admin at] För Rosén Håkan
> Skickat: den 7 oktober 2003 16:05
> Till: 'jdom-interest at'
> Ämne: [jdom-interest] Merging JDOM documents
> Hi,
> I'm trying to merge two documents and then transform them 
> into a result.
> some code:
> public Document setReports(Document inReport, Document rules) 
>                    throws Exception {
>   // insert incoming rules into inReport
>   inReport.getRootElement().getChild("employee").addContent
>                         (rules.getRootElement().detach());
>   Transformer transformer = TransformerFactory.newInstance().
>           newTransformer(new StreamSource("prepare.xsl"));
>   JDOMSource source = new JDOMSource(inReport);
>   JDOMResult result = new JDOMResult();
>   transformer.transform(source, result);
>   return result.getDocument();
> }
> The Document 'rules' is stored in my a servletContext and 
> only read once, The code works fine the first time, but the 
> second time I get an error that the root element is not set. 
> please help regards 
> /Håkan
> _______________________________________________
> To control your jdom-interest membership: 
uraddr at

More information about the jdom-interest mailing list