  | 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
|
|
|
  | | | Merge two different XML document | Merge two different XML document 2007-11-15 - By Jasmin_Mehta@(protected)
Back 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! ******************************************************************************
<br><font size=2 face="sans-serif">Hi,</font> <br> <br><font size=2 face="sans-serif">I have two XML document as listed below:< /font> <br> <br><font size=2 face="sans-serif">1) (xmlDocA)</font> <br> <br><font size=2 face="sans-serif"><GLogXMLElement></font> <br><font size=2 face="sans-serif"><Location></font> <br><font size=2 face="sans-serif"> <TransactionCode> ;NP</TransactionCode></font> <br><font size=2 face="sans-serif"> <LocationGid>< /font> <br><font size=2 face="sans-serif"> <Gid> ;</font> <br><font size=2 face="sans-serif"> <Xid>Rockville</Xid></font> <br><font size=2 face="sans-serif"> </Gid ></font> <br><font size=2 face="sans-serif"> </LocationGid>< /font> <br><font size=2 face="sans-serif"> <Address></font> <br><font size=2 face="sans-serif"> < ;AddressLines></font> <br><font size=2 face="sans-serif"> <SequenceNumber>2442</SequenceNumber></font> <br><font size=2 face="sans-serif"> <AddressLine>1221 E Otem Circle</AddressLine></font> <br><font size=2 face="sans-serif"> < /AddressLines></font> <br><font size=2 face="sans-serif"> <City >Miami</City></font> <br><font size=2 face="sans-serif"> < ;ProvidenceCode>FL</ProvidenceCode></font> <br><font size=2 face="sans-serif"> < ;PostalCode>91991</PostalCode></font> <br><font size=2 face="sans-serif"> </Address></font> <br><font size=2 face="sans-serif"></Location></font> <br><font size=2 face="sans-serif"></GLogXMLElement></font> <br> <br><font size=2 face="sans-serif">2) (xmlDocB)</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 color=blue 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">I want to merge document 1) in to document 2) under <TransmissionBody> element. </font> <br> <br><font size=2 face="sans-serif">Is it possible?</font> <br> <br><font size=2 face="sans-serif">When I try to do that I get </font><font size=2 color=red face="sans-serif">org.jdom.IllegalAddException: The Content already has an existing parent</font> <br> <br><font size=2 face="sans-serif">Code:</font> <br> <br><font size=2 face="sans-serif"> SAXBuilder saxBuilder = new SAXBuilder();</font> <br><font size=2 face="sans-serif"> java.io.File xmlFile = new File("xmlDocA");</font> <br><font size=2 face="sans-serif"> org.jdom.Document xmlDocumentA = saxBuilder.build(xmlFile);</font> <br> <br><font size=2 face="sans-serif"> xmlFile = new File("xmlDocB");</font> <br><font size=2 face="sans-serif"> org.jdom.Document xmlDocumentB = saxBuilder.build(xmlFile);</font> <br> <br><font size=2 face="sans-serif"> Element rootA = xmlDocumentA.getRootElement();</font> <br><font size=2 face="sans-serif"> List childrenDocA = rootA.getChildren();</font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> Element rootB = xmlDocumentB.getRootElement();</font> <br><font size=2 face="sans-serif"> Element childDocB = rootB.getChild("TransmissionBody");</font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 color=red face="sans-serif"> childDocB.addContent(childrenDocA); -- ---- ---- ---- Exception at this line</font> <br> <br><font size=2 face="sans-serif"> XMLOutputter xmlOutPutter = new XMLOutputter(Format.getPrettyFormat());</font> <br><font size=2 face="sans-serif"> xmlOutPutter .output(xmlDocumentB, System.out);</font> <br> <br><font size=2 face="sans-serif">Thanks</font> <br><font size=2 face="sans-serif">Jasmin</font> <br> <br> <br><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)
|
|
 |