private void deepCopy ( Element origElement , Element copyElement ) { List < Node > children = origElement . getChildElements ( ) ; for ( Node node : children ) { try { if ( node instanceof Content ) { Content content = ( Content ) ( ( Content ) node ) . clone ( ) ; copyElement . addChildElement ( content ) ; } else { Element element = ( Element ) ( ( Element ) node ) . clone ( ) ; copyElement . addChildElement ( element ) ; deepCopy ( ( Element ) node , element ) ; } } catch ( CloneNotSupportedException e ) { throw new XmlModelException ( "Unable to clone object" , e ) ; } } }
Deep copy recursive helper method .