  | 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 Jason Hunter
Back http://jdom.org/docs/faq.html#a0230
-jh-
Jasmin_Mehta@(protected) wrote: > > 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! > ***************************************************************************** *** > > > -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- > > __ ____ ____ ____ ____ ____ ____ ____ ____ ____ > To control your jdom-interest membership: > http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected) __ ____ ____ ____ ____ ____ ____ ____ ____ ____ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
|
|
 |