Closed
Description
I have the following use case:
require 'socket'
require 'rexml/parsers/pullparser'
# Server setup for demonstration purposes
server = TCPServer.new 2000
Thread.new do
client = server.accept
client.puts "<message>First valid and complete message</message>"
sleep 1
client.puts "<message>Second valid and complete message</message>"
sleep 1
client.puts "<message>Third valid and complete message</message>"
client.close
end
# Client setup
socket = TCPSocket.new 'localhost', 2000
# REXML PullParser using socket
parser = REXML::Parsers::PullParser.new(socket)
begin
while parser.has_next?
event = parser.pull
if event.start_element? and event[0] == 'message'
text = parser.pull
if text.text?
puts "Received message: #{text[0]}"
end
end
end
ensure
socket.close
end
# Closing the server in this demonstration
server.close
Here I have a socket, and I pull messages from the server and parse it. Every message is valid and complete xml.
Before the release https://github.com/ruby/rexml/releases/tag/v3.3.2 this use case worked like a charm. After that it doesn't work with exception
'REXML::Parsers::BaseParser#pull_event': Malformed XML: Extra tag at the end of the document (got '<message') (REXML::ParseException)
This is a side effect after this changes - #161
It seems there is no proper solution for this use case now, and I can't use the actual version of this gem.
Possible solutions could be as follows:
- Addition parameter or flag to ignore the error above.
- Add a special call to refresh the parser after each pull event.
Metadata
Metadata
Assignees
Labels
No labels