/** * extracts all text-elements of a particular element and returns an single string containing the contents of all * textelements and all character entity nodes. If a node is not known to the parser, its string value will be * delivered as <code>&entityname;</code>. * * @param e the element which is direct parent of all to be extracted textnodes. * @return the extracted String */ public static String getText( final Element e ) { final NodeList nl = e.getChildNodes(); final StringBuilder result = new StringBuilder( 100 ); for ( int i = 0; i < nl.getLength(); i++ ) { final Node n = nl.item( i ); if ( n.getNodeType() == Node.TEXT_NODE ) { final Text text = (Text) n; result.append( text.getData() ); } else if ( n.getNodeType() == Node.ENTITY_REFERENCE_NODE ) { result.append( '&' ); result.append( n.getNodeName() ); result.append( ';' ); } } return XML_ENTITIES.decodeEntities( result.toString() ); }
final String replaceString = lookupCharacter( entity ); if ( replaceString != null ) { bufValue.append( decodeEntities( replaceString ) ); } else { bufValue.append( '&' );