You have to clone and detach the child from its parent element before adding it to the new parent.
You have to clone and detach the child from its parent element before adding it to the new parent: html. AddContent(((Element)child.clone()).detach()).
Thank you for your support. It is working,but outputfile is blured. I've added output xml as updated question.
Could you please go through that... – Arsree Mar 9 at 15:36 take a look at your input and output. Your recursion is unnecessary. If you want to add a node (and all of its content) as a child to another element, you just really need to do only one addContent (after you've cloned and detached the original node).
However, this is another kind of problem; I've answered to your original question with my solution, which works. Then you've edited your question, and now your issue looks very different. I think this is not the right way to proceed.
Have a great day. – javanna Mar 10 at 9:12 actually I got a mistake about that. Till this time I was working with that recursion.
That's why I thought related to it. Now only-when you said about this-i get clarity about that. Really thank you @javanna.
That's very kind of you. Have a nice day.. – Arsree Mar 10 at 9:36.
The issue is here: Element child = (Element) iterator.next(); System.out. Println(child); html. AddContent(child); child is reference to the body element of the original xml document.
Its parent is myhtml You cannot add this as child of another new element in this way. You need to create a new element for the new xml document. I suggest you to study on "Reference" in Java.
Thank you @Sarwar Erfan... Could you give me or suggest a material to study about it. – Arsree Mar 9 at 8:24 javafaq. Nu/java-article436.
Html – Sarwar Erfan Mar 9 at 9:46 Thanks @Sarwar Erfan..I went through the material that you have sent. It was very useful one. But still I couldn't solve my problem.
I want elements with attributes from one xml file(body) to new xml file. Now I am using JDOM parser. I tried all methods i.e.AddContent(),setContent() etc.But I couldn't manage to get the output.
If you know about that could you help me to solve this problem? – Arsree Mar 9 at 12:34.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.