SV: [jdom-interest] Merging JDOM documents

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


Hi,

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

You must either clone the element

   inReport.getRootElement().getChild("employee").addContent
                         (Element)(rules.getRootElement().clone());

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.

/mvh
   Per Norrman


> -----Ursprungligt meddelande-----
> Från: jdom-interest-admin at jdom.org 
> [mailto:jdom-interest-admin at jdom.org] För Rosén Håkan
> Skickat: den 7 oktober 2003 16:05
> Till: 'jdom-interest at jdom.org'
> Ä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: 
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com




More information about the jdom-interest mailing list