  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | How to build multiple XML documents by mergeing two XML document | How to build multiple XML documents by mergeing two XML document 2007-11-23 - By Jasmin_Mehta@(protected)
Back 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! ******************************************************************************
<br><font size=2 face="sans-serif">I am building multiple dynamic xml documents from result set and storing them to an ArrayList called 'xmlDocumentList'.< /font> <br><font size=2 face="sans-serif">I have another static xml document called 'staticDocument'. Where static document looks like:</font> <br> <br><font size=2 face="sans-serif"><Transmission></font> <br><font size=2 face="sans-serif"> <TransmissionHeader ></font> <br><font size=2 face="sans-serif"> <UserName /></font> <br><font size=2 face="sans-serif"> <Password /></font> <br><font size=2 face="sans-serif"> < /TransmissionHeader></font> <br><font size=2 face="sans-serif"> <TransmissionBody> ;</font> <br><font size=2 face="sans-serif"> <!-- -- here goes GLogXMLElement XML element ----></font> <br><font size=2 face="sans-serif"> </TransmissionBody ></font> <br><font size=2 face="sans-serif"> </Transmission></font> <br> <br><font size=2 face="sans-serif">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'.</font> <br> <br><font size=2 face="sans-serif">-- ---- ---- ---- ---- ---- ---- ---- ------ -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- -- ---</font> <br><font size=2 face="sans-serif"> ArrayList dynamicDocumentList = xmlBuilder.getDynamicXmlDocuments();</font> <br><font size=2 face="sans-serif"> Document staticDocument = xmlBuilder.getStaticXmlWrapper();</font> <br><font size=2 face="sans-serif"> ArrayList finalDocumentList = new ArrayList(); </font> <br><font size=2 face="sans-serif"> Element staticRoot = staticDocument.getRootElement();</font> <br><font size=2 face="sans-serif"> Element staticChild = staticRoot.getChild("TransmissionBody");</font> <br><font size=2 face="sans-serif"> Element dynamicRoot = null;</font> <br><font size=2 face="sans-serif"> for(int i = 0; i < dynamicDocumentList.size(); i++)</font> <br><font size=2 face="sans-serif"> {</font> <br><font size=2 face="sans-serif"> dynamicRoot = ((Document)dynamicDocumentList.get(i)).getRootElement();</font> <br><font size=2 face="sans-serif"> staticChild.addContent(dynamicRoot.detach()); </font> <br><font size=2 face="sans-serif">   ;finalDocumentList.add(staticDocument);</font> <br><font size=2 face="sans-serif"> }</font> <br><font size=2 face="sans-serif"> FileOutputStream finalXmlFile = null;</font> <br><font size=2 face="sans-serif"> XMLOutputter xmlOutPutter = null;</font> <br><font size=2 face="sans-serif"> for (int i = 0; i < finalDocumentList.size(); i++)</font> <br><font size=2 face="sans-serif"> {</font> <br><font size=2 face="sans-serif"> finalXmlFile = new FileOutputStream("F:\\JavaProjects\\WorkspaceDev\ \OTM\\xsl\\GLogFinal"+i+".xml");</font> <br><font size=2 face="sans-serif"> xmlOutPutter = new XMLOutputter(Format.getPrettyFormat());</font> <br><font size=2 face="sans-serif"> xmlOutPutter.output((Document)(finalDocumentList.get(i)), finalXmlFile);</font> <br><font size=2 face="sans-serif"> } </font><p><font size="1"><font face="arial,helvetica,sans-serif"><strong> ****************************************************************************** <br /></strong><font color="#ff0000">ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION</font> <br />Our domain name is changing.? Please take note of the sender's<br />e-Mail address and make changes to your personal address list,<br />if needed.? Both domains will continue to work, only for a limited<br />time. <br />************************************************************************** ****<br />This email and any files transmitted with it are intended solely for <br />the use of the individual or agency to whom they are addressed. <br />If you have received this email in error please notify the Navy <br />Exchange Service Command e-mail administrator. This footnote <br />also confirms that this email message has been scanned for the<br />presence of computer viruses.< /font></font></p><p><font size="1"><font face="arial,helvetica,sans-serif">Thank You!??????????? <br /><strong>************************************************* *****************************</strong></font></font></p>
__ ____ ____ ____ ____ ____ ____ ____ ____ ____ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
|
|
 |