[jdom-interest] Merge two different XML document
    Jasmin_Mehta at nexweb.org 
    Jasmin_Mehta at nexweb.org
       
    Thu Nov 15 11:50:15 PST 2007
    
    
  
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!            
******************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20071115/84e8a722/attachment.htm
    
    
More information about the jdom-interest
mailing list