<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1587" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=449262009-05042007>Hello,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=449262009-05042007>Please find below the code. This might be of some
help.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=449262009-05042007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=449262009-05042007>@param duplicateNo: number of times the child has to be
added or duplicated.</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=449262009-05042007>@param parent: parent of the duplicate
element</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=449262009-05042007>@param <SPAN
class=449262009-05042007>d</SPAN>uplicateElement: child element which has to be
duplicated</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=449262009-05042007></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT><FONT face=Arial><FONT color=#0000ff><FONT
size=2>private void duplicateElement(int duplicateNo, Element <SPAN
class=449262009-05042007>p</SPAN>arent, Element <SPAN
class=449262009-05042007>d</SPAN>uplicateElement){<BR>
try{<BR>
<BR> int index
= <SPAN class=449262009-05042007>p</SPAN>arent.indexOf(<SPAN
class=449262009-05042007>d</SPAN>uplicateElement);<BR>
for(int i=0; i< duplicateNo;
i++)<BR>
{ <BR> <BR>
//get the contents from the parent to a local
variable.<BR>
Element parentClone = (Element)<SPAN
class=449262009-05042007>d</SPAN>uplicateElement.clone();<BR>
//add the modified element to the <SPAN
class=449262009-05042007>p</SPAN>arent
element<BR> <SPAN
class=449262009-05042007>p</SPAN>arent.addContent(index,(Element)parentClone); <BR> index
= <SPAN class=449262009-05042007>p</SPAN>arent.indexOf(<SPAN
class=449262009-05042007>d</SPAN>uplicateElement);<BR>
<BR>
} <BR>
<BR> //now
remove the parent
element.<BR> <SPAN
class=449262009-05042007>p</SPAN>arent.removeContent(<SPAN
class=449262009-05042007>d</SPAN>uplicateElement); <BR> <BR>
}catch (Exception e) {<BR><SPAN
class=449262009-05042007>
e.printStackTrace();</SPAN></FONT></FONT></FONT></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff size=2><SPAN
class=449262009-05042007></SPAN>
}<BR> }</FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial color=#0000ff
size=2></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=449262009-05042007><FONT face=Arial
color=#0000ff size=2>Regards,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=449262009-05042007><FONT face=Arial
color=#0000ff size=2>Deepa</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> jdom-interest-bounces@jdom.org
[mailto:jdom-interest-bounces@jdom.org] <B>On Behalf Of </B>Normadiah
Mahiddin<BR><B>Sent:</B> Thursday, 5. April 2007 11:29 AM<BR><B>To:</B>
jdom-interest@jdom.org<BR><B>Subject:</B> [jdom-interest] How to add same
children element in existing XMLfile?<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV>Dear all,</DIV>
<DIV>who knows on how to add same children element in existing XML file?</DIV>
<DIV>Thank you very much for your help.</DIV>
<DIV> </DIV>
<DIV>Regards,</DIV>
<DIV>Normadiah Mahiddin</DIV></BODY></HTML>