public String text ( ) { if ( value instanceof String ) { return ( String ) value ; } if ( value instanceof NodeList ) { return ( ( NodeList ) value ) . text ( ) ; } if ( value instanceof Collection ) { Collection coll = ( Collection ) value ; String previousText = null ; StringBuilder sb = null ; for ( Object child : coll ) { String childText = null ; if ( child instanceof String ) { childText = ( String ) child ; } else if ( child instanceof Node ) { childText = ( ( Node ) child ) . text ( ) ; } if ( childText != null ) { if ( previousText == null ) { previousText = childText ; } else { if ( sb == null ) { sb = new StringBuilder ( ) ; sb . append ( previousText ) ; } sb . append ( childText ) ; } } } if ( sb != null ) { return sb . toString ( ) ; } else { if ( previousText != null ) { return previousText ; } return "" ; } } return "" + value ; }
Returns the textual representation of the current node and all its child nodes .