public static String getElementContent ( Element element , String defaultStr ) throws Exception { if ( element == null ) return defaultStr ; NodeList children = element . getChildNodes ( ) ; String result = "" ; for ( int i = 0 ; i < children . getLength ( ) ; i ++ ) { if ( children . item ( i ) . getNodeType ( ) == Node . TEXT_NODE || children . item ( i ) . getNodeType ( ) == Node . CDATA_SECTION_NODE ) { result += children . item ( i ) . getNodeValue ( ) ; } else if ( children . item ( i ) . getNodeType ( ) == Node . COMMENT_NODE ) { // Ignore comment nodes } } return result . trim ( ) ; }
Get the content of the given element .