Message
Hi
All,
I am trying to append an element ( I'm calling it common element ) at
multiple places in the DOM hierarchy. But it seems
DOM is not accepting the same element at
multiple places. In the output it always has only one common element.
Here is some more detailed analysis what I was trying to do:-
Document doc= new
DocumentImpl();
Element root = doc.createElement("set");
Element common = doc.createElement("common"); //This is common element
Element book2 = doc.createElement("book2");
Element book1 = doc.createElement("book1");
Element document1 = doc.createElement("document");
document1.appendChild(
common ); //append
common element under document1
book1.appendChild( common ); //append common element
under book1
book1.appendChild( document1 );
root.appendChild( book1 );
root.appendChild( book2 );
doc.appendChild( root );
OUTPUT is:-
<set><book1><common/><document/></book1><book2/></set>
common element is not getting
appended to the document1
Is there any such restriction that same element can't be appended at
more than one place ?
I tried by cloning the common element and
then appending under document1 , but still
no luck.
Then I added one more common element
in the end as:-
book2.appendChild( common );
OUTPUT is:-
<set><book1><document/></book1><book2><common/></book2></set>
One interested thing I observed is
that it always appends the common element
for the last appendChild() call only!!
Any
help or any pointers in this regard will be greatly appreciated.
Thanks,
Anoop Singh