[jdom-interest] How to add same children element in existing XMLfile?

Deepa Janamatti (RBIN/EMT2) Deepa.Janamatti at in.bosch.com
Thu Apr 5 02:28:02 PDT 2007


Hello,
Please find below the code. This might be of some help.
 
@param duplicateNo: number of times the child has to be added or
duplicated.
@param parent: parent of the duplicate element
@param duplicateElement: child element which has to be duplicated
 
private void duplicateElement(int duplicateNo, Element parent, Element
duplicateElement){
        try{
            
            int index = parent.indexOf(duplicateElement);
            for(int i=0; i< duplicateNo; i++)
            {   
                               
                //get the contents from the parent to a local variable.
                Element parentClone = (Element)duplicateElement.clone();
                //add the modified element to the parent element
                parent.addContent(index,(Element)parentClone);

                index = parent.indexOf(duplicateElement);
                  
            }       
    
            //now remove the parent element.
            parent.removeContent(duplicateElement);            
            
        }catch (Exception e) {
           e.printStackTrace();
        }
    }
 
Regards,
Deepa

________________________________

From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Normadiah Mahiddin
Sent: Thursday, 5. April 2007 11:29 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] How to add same children element in existing
XMLfile?


Dear all,
who knows on how to add same children element in existing XML file?
Thank you very much for your help.
 
Regards,
Normadiah Mahiddin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20070405/f15e9709/attachment.htm


More information about the jdom-interest mailing list