[jdom-interest] How to build multiple XML documents by mergeing two XML documents using JDOM

Grzegorz Kaczor grzegorz.kaczor at gmail.com
Fri Nov 23 12:36:47 PST 2007


Hi,

I think you should clone the staticDocument before running each merge. Now
you have the same staticDocument stored multiple times in the
finalDocumentList so all the output files are identical.

Regards,
GK

2007/11/23, Jasmin_Mehta at nexweb.org <Jasmin_Mehta at 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/youraddr@yourhost.com
>



-- 
"Choć tyle wiemy własnym doświadczeniem:
W nas jest Raj, Piekło - i do obu - szlaki."
J.K.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20071123/aa192c0c/attachment.htm


More information about the jdom-interest mailing list