public static String getOnlyTextContent ( NodeList list ) throws XMLRPCException { StringBuilder builder = new StringBuilder ( ) ; Node n ; for ( int i = 0 ; i < list . getLength ( ) ; i ++ ) { n = list . item ( i ) ; // Skip comments inside text tag. if ( n . getNodeType ( ) == Node . COMMENT_NODE ) { continue ; } if ( n . getNodeType ( ) != Node . TEXT_NODE ) { throw new XMLRPCException ( "Element must contain only text elements." ) ; } builder . append ( n . getNodeValue ( ) ) ; } return builder . toString ( ) ; }
Returns the text node from a given NodeList . If the list contains more then just text nodes an exception will be thrown .