Java Mailing List Archive

http://www.junlu.com/

Google
Google
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
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Merge two different XML document

Merge two different XML document

2007-11-15       - By Jasmin_Mehta@(protected)

 Back
Reply:     1     2  

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) &nbsp;(xmlDocA)</font>
<br>
<br><font size=2 face="sans-serif">&lt;GLogXMLElement&gt;</font>
<br><font size=2 face="sans-serif">&lt;Location&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp;&lt;TransactionCode&gt
;NP&lt;/TransactionCode&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &lt;LocationGid&gt;<
/font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;Gid&gt
;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&lt;Xid&gt;Rockville&lt;/Xid&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/Gid
&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &lt;/LocationGid&gt;<
/font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &lt;Address&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt
;AddressLines&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&lt;SequenceNumber&gt;2442&lt;/SequenceNumber&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&lt;AddressLine&gt;1221 E Otem Circle&lt;/AddressLine&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;
/AddressLines&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;City
&gt;Miami&lt;/City&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt
;ProvidenceCode&gt;FL&lt;/ProvidenceCode&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt
;PostalCode&gt;91991&lt;/PostalCode&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &lt;/Address&gt;</font>
<br><font size=2 face="sans-serif">&lt;/Location&gt;</font>
<br><font size=2 face="sans-serif">&lt;/GLogXMLElement&gt;</font>
<br>
<br><font size=2 face="sans-serif">2) &nbsp; &nbsp; (xmlDocB)</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &lt;Transmission
&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &lt
;TransmissionHeader&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &lt;UserName /&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &lt;Password /&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;
/TransmissionHeader&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &lt
;TransmissionBody&gt;</font>
<br><font size=2 color=blue face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;
&lt;!-- -- here goes GLogXMLElement XML element ----&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &lt;
/TransmissionBody&gt;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp;&lt;/Transmission&gt;</font>
<br>
<br><font size=2 face="sans-serif">I want to merge document 1) in to document
2) under &lt;TransmissionBody&gt; 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">&nbsp; &nbsp; &nbsp; &nbsp; SAXBuilder
saxBuilder = new SAXBuilder();</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; java.io.File
xmlFile = new File(&quot;xmlDocA&quot;);</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; org.jdom.Document
xmlDocumentA = saxBuilder.build(xmlFile);</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; xmlFile
= new File(&quot;xmlDocB&quot;);</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; org.jdom.Document
xmlDocumentB = saxBuilder.build(xmlFile);</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Element
rootA = xmlDocumentA.getRootElement();</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; List childrenDocA
= rootA.getChildren();</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; </font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Element
rootB = xmlDocumentB.getRootElement();</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Element
childDocB = rootB.getChild(&quot;TransmissionBody&quot;);</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;</font>
<br><font size=2 color=red face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;
childDocB.addContent(childrenDocA); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- ---- ---- ----
Exception at this line</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; XMLOutputter
xmlOutPutter = new XMLOutputter(Format.getPrettyFormat());</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; 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)

©2008 junlu.com - Jax Systems, LLC, U.S.A.