Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

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

Deepa Janamatti (RBIN/EMT2)

2007-04-05

Replies:

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@jdom.org [mailto:jdom-interest-bounces@jdom.org] On Behalf Of Normadiah Mahiddin
Sent: Thursday, 5. April 2007 11:29 AM
To: jdom-interest@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
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.