# File nqxml/treeparser.rb, line 98
 def handleNextEntity(entity)
	    if @documentSection == DOCUMENT_PROLOG:DOCUMENT_PROLOG
		isDocType = entity.instance_of?(Doctype)
		if !miscEntity?(entity) && !isDocType
		    @documentSection = DOCUMENT_BODY:DOCUMENT_BODY
		    # ...continue processing this as a body tag
		else
		    if isDocType && !@document.doctype.nil?
			raise ParserError.new("multiple DOCTYPE tags seen",
					      @tokenizer)
		    end
		    @document.addToProlog(entity)
		    return
		end
	    end

	    if @documentSection == DOCUMENT_EPILOGUE:DOCUMENT_EPILOGUE
		if !miscEntity?(entity)
		    str = "entity of type #{entity.class} seen after" +
			" document's root node"
		    raise ParserError.new(str, @tokenizer)
		end
		@document.addToEpilogue(entity)
		return
	    end

	    # We are in the body of the document.
	    if entity.instance_of?(Tag)
		handleTag(entity)
		return
	    end

	    # From here down, we have any entity except a Tag.
	    if entity.instance_of?(Doctype)
		str = 'DOCTYPE seen in document prolog'
		raise ParserError.new(str, @tokenizer)
	    end

	    # Add this entity to parent. If parent is nil, then we have a
	    # problem: the entity isn't a tag, therefore it can't be the
	    # root node.
	    parent = @nodeStack.last
	    if parent.nil?
		str = "unexpected entity of type '#{entity.class}' seen" +
		    " outside of root node"
		raise ParserError.new(str, @tokenizer)
	    end
	    parent.addChild(entity)
	end