Re: Merge two different XML document

Jason Hunter <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
http://jdom.org/docs/faq.html#a0230

-jh-

[email protected] wrote:
> 
> Hi,
> 
> I have two XML document as listed below:
> 
> 1)  (xmlDocA)
> 
> <GLogXMLElement>
> <Location>
>      <TransactionCode>NP</TransactionCode>
>       <LocationGid>
>          <Gid>
>             <Xid>Rockville</Xid>
>          </Gid>
>       </LocationGid>
>       <Address>
>          <AddressLines>
>             <SequenceNumber>2442</SequenceNumber>
>             <AddressLine>1221 E Otem Circle</AddressLine>
>          </AddressLines>
>          <City>Miami</City>
>          <ProvidenceCode>FL</ProvidenceCode>
>          <PostalCode>91991</PostalCode>
>       </Address>
> </Location>
> </GLogXMLElement>
> 
> 2)     (xmlDocB)
> 
>         <Transmission>
>         <TransmissionHeader>
>                   <UserName />
>                   <Password />
>           </TransmissionHeader>
>         <TransmissionBody>
>         <!----- here goes GLogXMLElement XML element ---->
>         </TransmissionBody>
>    </Transmission>
> 
> I want to merge document 1) in to document 2) under <TransmissionBody> 
> element.
> 
> Is it possible?
> 
> When I try to do that I get org.jdom.IllegalAddException: The Content 
> already has an existing parent
> 
> Code:
> 
>         SAXBuilder saxBuilder = new SAXBuilder();
>         java.io.File xmlFile = new File("xmlDocA");
>         org.jdom.Document xmlDocumentA = saxBuilder.build(xmlFile);
> 
>         xmlFile = new File("xmlDocB");
>         org.jdom.Document xmlDocumentB = saxBuilder.build(xmlFile);
> 
>         Element rootA = xmlDocumentA.getRootElement();
>         List childrenDocA = rootA.getChildren();
>        
>         Element rootB = xmlDocumentB.getRootElement();
>         Element childDocB = rootB.getChild("TransmissionBody");
>        
>         childDocB.addContent(childrenDocA);                             
> ----------------- Exception at this line
> 
>         XMLOutputter xmlOutPutter = new 
> XMLOutputter(Format.getPrettyFormat());
>         xmlOutPutter.output(xmlDocumentB, System.out);
> 
> Thanks
> Jasmin
> 
> 
> *******************************************************************************
> *ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION
> Our domain name is changing.  Please take note of the sender's
> e-Mail address and make changes to your personal address list,
> if needed.  Both domains will continue to work, only for a limited
> time.
> ******************************************************************************
> This email and any files transmitted with it are intended solely for
> the use of the individual or agency to whom they are addressed.
> If you have received this email in error please notify the Navy
> Exchange Service Command e-mail administrator. This footnote
> also confirms that this email message has been scanned for the
> presence of computer viruses.
> 
> Thank You!           
> ********************************************************************************
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/[email protected]
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.