private static void getRichText ( Node node , StringBuilder builder ) { Node n = node . getFirstChild ( ) ; while ( n != null ) { if ( n . getNodeType ( ) == Node . TEXT_NODE ) { builder . append ( n . getNodeValue ( ) ) ; } else if ( n . getNodeType ( ) == Node . ELEMENT_NODE ) { builder . append ( ' ' ) ; builder . append ( n . getNodeName ( ) ) ; builder . append ( ' ' ) ; getRichText ( n , builder ) ; builder . append ( ' ' ) ; builder . append ( ' ' ) ; builder . append ( n . getNodeName ( ) ) ; builder . append ( ' ' ) ; } n = n . getNextSibling ( ) ; } }
Extract rich text content from given node . It is not expected that rich text HTML formatting tags to have attributes and this builder just ignore them . Also ignores all other node types beside text and elements .