private String advanceAndParseText ( ) throws Exception { StringBuilder buf = new StringBuilder ( ) ; while ( reader . hasNext ( ) ) { XMLEvent event = nextEvent ( "text " ) ; if ( event . isCharacters ( ) ) { buf . append ( event . asCharacters ( ) . getData ( ) ) ; } else if ( event . isEndElement ( ) ) { return buf . toString ( ) ; } else if ( event . isStartElement ( ) ) { throw new IllegalArgumentException ( "Unexpected start tag" ) ; } } throw new IllegalArgumentException ( "Unexpected end of document" ) ; }
reader must be at StartElement