|
# File jabber4r/protocol.rb, line 1213
def parse
@started = false
parser = XMLParser.new("UTF-8")
def parser.unknownEncoding(e)
raise "Unknown encoding #{e.to_s}"
end
def parser.default
end
begin
parser.parse(@stream) do |type, name, data|
begin
case type
when XMLParser::START_ELEM
case name
when "stream:stream"
openstream = ParsedXMLElement.new(name)
data.each {|key, value| openstream.add_attribute(key, value)}
@listener.receive(openstream)
@started = true
else
if @current.nil?
@current = ParsedXMLElement.new(name.clone)
else
@current = @current.add_child(name.clone)
end
data.each {|key, value| @current.add_attribute(key.clone, value.clone)}
end
when XMLParser::CDATA
@current.append_data(data.clone) if @current
when XMLParser::END_ELEM
case name
when "stream:stream"
@started = false
else
@listener.receive(@current) unless @current.element_parent
@current = @current.element_parent
end
end
rescue
puts "Error #{$!}"
end
end
rescue XMLParserError
line = parser.line
print "XML Parsing error(#{line}): #{$!}\n"
end
end
|