This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes JDOM: attach Content to other Element? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "JDOM: attach Content to other Element?" Watch "JDOM: attach Content to other Element?" New topic
Author

JDOM: attach Content to other Element?

Lukas Benberg
Ranch Hand

Joined: Jan 03, 2007
Posts: 45
hello all,
i have a JDOM Document. i would like to add the content of this document's root element to the root element of another document. here is my attempt:



Exception in thread "main" org.jdom.IllegalAddException: The Content already has an existing parent "elem"

how can i do this?
thank you!
rodd manning
Greenhorn

Joined: Mar 06, 2007
Posts: 15
Hi,
I had faced a similar issue when i was working with JDOM, and i tried working with the detach() method, but was unsuccessful.The following approach will solve your problem
i also found another solution:

// get content of root element
List content = doc1.getRootElement().cloneContent();

cloneContent() instead of getContent() does it. you don't have to detach then.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDOM: attach Content to other Element?
 
Similar Threads
how to use DOM Parser
Simple XSL transformation
Problem Overwriting XML Section
JDOM works normally not with JSP
Read data to the xml file from the database?