question: protected Element parseCommentOrXMLDeclaration ( Reader is , String endTag ) throws IOException { char endTagChars [ ] = endTag . toCharArray ( ) ; int endTagPos = 0 ; StringBuilder text = new StringBuilder ( ) ; boolean ended = false ; while ( ! ended ) { int in = read ( is ) ; if ( in == - 1 ) { break ; } char c = ( char ) in ; if ( c == endTagChars [ endTagPos ] ) { endTagPos ++ ; if ( endTagPos == endTagChars . length ) { ended = true ; } } else { if ( endTagPos != 0 ) { if ( c == endTagChars [ 0 ] && endTagPos > 1 ) { text . append ( c ) ; continue ; } text . append ( endTagChars , 0 , endTagPos ) ; endTagPos = 0 ; } text . append ( c ) ; } } String elementName = null ; if ( endTag . equals ( "-->" ) ) { elementName = "comment" ; } else if ( endTag . equals ( ">" ) ) { elementName = "XML declaration" ; } else { if ( eventParser ) { textElement ( text . toString ( ) ) ; return null ; } return createNewTextElement ( text . toString ( ) ) ; } if ( eventParser ) { return null ; } Element comment = createNewElement ( elementName ) ; comment . setAttribute ( "content" , text . toString ( ) ) ; comment . isComment = true ; return comment ; }
target:  This utility method is used to parse comments and XML declarations in the XML. The comment/declaration is returned as an Element, but is flagged as a comment since both comments and XML declarations are not part of the XML DOM. This method can be overridden to process specific XML declarations