public static void removeAllChildren ( final Node node ) { assert node != null ; assert node . getNodeType ( ) != Node . ATTRIBUTE_NODE ; if ( node . getNodeType ( ) == Node . DOCUMENT_TYPE_NODE ) { Element documentElement = ( ( Document ) node ) . getDocumentElement ( ) ; if ( documentElement != null ) { ( ( Document ) node ) . removeChild ( documentElement ) ; } return ; } if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { Element element = ( Element ) node ; for ( Node n = element . getFirstChild ( ) ; n != null ; n = element . getFirstChild ( ) ) { element . removeChild ( n ) ; } } }
Simply removes all child nodes .