How to build multiple XML documents by mergeing two XML documents using JDOM

[email protected]
Newsgroups gmane.comp.java.jdom.general
Message-ID <OFA355C039.B1938A83-ON8525739C.00534B19-8525739C.00538BCC@nexweb.org>
I am building multiple dynamic xml documents from result set and storing 
them to an ArrayList called 'xmlDocumentList'.
I have another static xml document called 'staticDocument'. Where static 
document looks like:

<Transmission>
      <TransmissionHeader>
              <UserName />
              <Password />
        </TransmissionHeader>
      <TransmissionBody>
      <!----- here goes GLogXMLElement XML element ---->
      </TransmissionBody>
   </Transmission>

Now I want to create another ArrayList 'finalDocumentList' out of mergeing 
'staticDocument' with each element of 'xmlDocumentList'. That will be like 
each element of 'finalDocumentList' is made from merging 'staticDocument' 
with 'xmlDocumentList[i]' (one of dynamic document element) at 
<TransmissionBody>. When I do that with attached code snippet, it creates 
the GlogFinal0.xml, GlogFinal1, GlogFinal2..etc file with all having same 
content in them. It uses only first element of 'xmlDocumentList' to build 
all elements of 'finalDocumentList'.

----------------------------------------------------------------------------------------------------------------------------------
        ArrayList dynamicDocumentList = 
xmlBuilder.getDynamicXmlDocuments();
        Document staticDocument = xmlBuilder.getStaticXmlWrapper();
        ArrayList finalDocumentList = new ArrayList(); 
        Element staticRoot = staticDocument.getRootElement();
        Element staticChild = staticRoot.getChild("TransmissionBody");
        Element dynamicRoot = null;
        for(int i = 0; i < dynamicDocumentList.size(); i++)
        {
            dynamicRoot = 
((Document)dynamicDocumentList.get(i)).getRootElement();
            staticChild.addContent(dynamicRoot.detach()); 
           finalDocumentList.add(staticDocument);
        }
          FileOutputStream finalXmlFile = null;
          XMLOutputter xmlOutPutter = null;
          for (int i = 0; i < finalDocumentList.size(); i++)
          {
            finalXmlFile =  new 
FileOutputStream("F:\\JavaProjects\\WorkspaceDev\\OTM\\xsl\\GLogFinal"+i+".xml");
            xmlOutPutter = new XMLOutputter(Format.getPrettyFormat());
            xmlOutPutter.output((Document)(finalDocumentList.get(i)), 
finalXmlFile);
          } 
******************************************************************************
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]
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.