question: Element renameElementAndImportChild ( Element source , Document targetDocument , String newName ) { Element newElement = targetDocument . createElement ( newName ) ; NamedNodeMap namedNodeMap = source . getAttributes ( ) ; for ( int iAttr = 0 ; iAttr < namedNodeMap . getLength ( ) ; iAttr ++ ) { Node node = namedNodeMap . item ( iAttr ) ; newElement . setAttribute ( node . getNodeName ( ) , node . getNodeValue ( ) ) ; } NodeList listofChilds = source . getChildNodes ( ) ; for ( int iChild = 0 ; iChild < listofChilds . getLength ( ) ; iChild ++ ) { Node node = listofChilds . item ( iChild ) ; newElement . appendChild ( targetDocument . importNode ( node , true ) ) ; } return newElement ; }
target:  Renames an element and imports its child nodes.