def parse(string)
unless Object.const_defined?('REXML')
require 'rexml/document'
require 'rexml/streamlistener'
if CGIKit::Application.respond_to?(:precede_iconv_as_rexml_encoding_module) and not(CGIKit::Application.precede_iconv_as_rexml_encoding_module)
require 'cgikit/lang/encoding-patch.rb'
end
end
@html_string = string
init_listener
@node = CGIKit::HTMLParser::RootNode.new
@cur = @node
@parser = REXML::Parsers::BaseParser.new(string)
begin
__parse
rescue REXML::ParseException
raise CGIKit::HTMLParser::HTMLParser::ParseError, "REXML raises Error when parsing #{@filename}.\nREXML error message: #{$!.to_s.gsub(/\r?\n/, ' ')}\n"
end
if @buf.size > 0
@cur << buffer2textnode
end
self.node
end