  | |  | Same element append at multiple places in DOM | Same element append at multiple places in DOM 2003-09-29 - By Singh, Anoop
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Message</TITLE> <META http-equiv=Content-Type content="text/html; charset=us-ascii"> <META content="MSHTML 6.00.2800.1170" name=GENERATOR></HEAD> <BODY> <DIV><FONT face=Arial size=2><SPAN class=689432323-29092003>Hi All,</SPAN></FONT></DIV> <DIV><FONT face=Arial size=2><SPAN class=689432323-29092003> I am trying to append an element ( I'm calling it common element ) at multiple places in the DOM hierarchy. But it seems </SPAN></FONT></DIV> <DIV><FONT face=Arial size=2><SPAN class=689432323-29092003> DOM </SPAN></FONT><FONT face=Arial size=2><SPAN class=689432323-29092003 >is not accepting the same element at multiple places. In the output it always has only one common element.</SPAN></FONT></DIV> <DIV><FONT face=Arial size=2><SPAN class=689432323-29092003> </SPAN></FONT><FONT face=Arial size=2><SPAN class=689432323-29092003></SPAN></FONT></DIV> <DIV><FONT face=Arial size=2><SPAN class=689432323-29092003> Here is some more detailed analysis what I was trying to do:-</SPAN></FONT></DIV> <DIV><FONT face=Courier size=2><SPAN class=689432323-29092003></SPAN></FONT> </DIV> <DIV><FONT face=Courier size=2> Document doc= new DocumentImpl();<BR> Element root = doc.createElement("set"); <BR> Element common = doc.createElement("common");<SPAN class=689432323-29092003> <FONT face=Arial>//This is common elemen</FONT>t</SPAN><BR> Element book2 = doc.createElement("book2"); <BR> Element book1 = doc.createElement("book1"); <BR> Element document1 = doc.createElement("document"); </FONT></DIV> <DIV><FONT face=Courier><FONT size=2><STRONG> <SPAN class=689432323-29092003> </SPAN></STRONG>document1.appendChild( common );<SPAN class=689432323-29092003> <FONT face=Arial>//append <FONT face=Courier>common</FONT> element under </FONT><FONT face=Courier>document1</FONT></SPAN><BR> book1.appendChild( common );<SPAN class=689432323-29092003> <FONT face=Arial>//append <FONT face=Courier>common</FONT> element under </FONT><FONT face=Courier>book1<BR></FONT></SPAN> book1.appendChild( document1 );<BR> root.appendChild( book1 );<BR> root.appendChild( book2 );   ; <BR> doc.appendChild( root ); </FONT></FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>OUTPUT is:<SPAN class=689432323-29092003>-</SPAN><BR><FONT face=Courier> <set><book1><common/><document/>< /book1><book2/></set></FONT> </FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial><FONT size=2><FONT face=Courier><SPAN class=689432323-29092003>c</SPAN>ommon</FONT> element is not getting appended to the <FONT face=Courier>document1</FONT> <BR>Is there any such restriction that same element can't be appended at more than one place ? <BR>I tried by cloning the <FONT face=Courier>common</FONT> element and then appending under <FONT face=Courier>document1</FONT> , but still no luck.</FONT></FONT></DIV> <DIV><FONT size=2></FONT><FONT size=2></FONT><FONT size=2></FONT><FONT size=2></FONT><FONT size=2></FONT><BR><FONT face=Arial size=2>Then I added one more <SPAN class=689432323-29092003><FONT face=Courier>common</FONT> element</SPAN> in the end as<SPAN class=689432323-29092003>:-</SPAN><BR><FONT face=Courier>book2.appendChild( common );</FONT> </FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>OUTPUT is:<SPAN class=689432323-29092003>-</SPAN><BR><FONT face=Courier><set><book1><document/></book1><book2 ><common/></book2></set></FONT></FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>One interested thing I observed is that it always appends the <FONT face=Courier>common</FONT> element for the last <FONT face=Courier>appendChild()</FONT> call only!!</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><SPAN class=689432323-29092003><FONT face=Arial size=2>Any help or any pointers in this regard will be greatly appreciated.</FONT></SPAN></DIV><!-- Converted from text/rtf format --> <P><FONT face=Arial><FONT color=#000080><FONT size=2><SPAN class=689432323-29092003>Thanks</SPAN>,</FONT></FONT></FONT> <BR><FONT face=Arial color=#ff9900 size=2>Anoop Singh</FONT> </P> <DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>
|
|
|