public static void requireEmptyText ( Node node , String errMsg ) throws IllegalArgumentException { require ( ( node instanceof Text ) || ( node instanceof Comment ) , errMsg + ": " + node . toString ( ) ) ; if ( node instanceof Text ) { Text text = ( Text ) node ; String textValue = text . getData ( ) ; require ( textValue . trim ( ) . length ( ) == 0 , errMsg + ": " + textValue ) ; } }
Assert that the given org . w3c . doc . Node is a comment element or a Text element and that it ontains whitespace only otherwise throw an IllegalArgumentException using the given error message . This is helpful when nothing is expected at a certain place in a DOM tree yet comments or whitespace text nodes can appear .