[rexml] parse_stream from Net::HTTP source

F

Frederic Logier

I have some problem with rexml. I want to use the stream parsing mode,
from an http_connect.get source.
Trouble is with a bad xml, which contains badly utf8 character.
When i open this xml from a local file, the stream parsing stop when it
encounter a bad ut8 character. It's exactly what i want.
But when i open this xml file from a Net::HTTP source, stream parsing
failed directly on utf8 error :

(eval):2:in `iconv': "\300\314\346\216\251 \346\215\256\307\337\346\217
\256 \300"... (Iconv::IllegalSequence)
from (eval):2:in `decode'
from /usr/lib/ruby/1.8/rexml/source.rb:43:in `encoding='
from /usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:202:in `pull'
from /usr/lib/ruby/1.8/rexml/parsers/streamparser.rb:16:in
`parse'
from /usr/lib/ruby/1.8/rexml/document.rb:171:in `parse_stream'
from test_stream_rexml_yp.rb:29

here my source code :


#!/bin/ruby

require 'net/http'
require "rexml/document"
require "rexml/streamlistener"
include REXML

class Handler
include StreamListener
def tag_start name, attrs
if name=="channel"
puts attrs["name"]
end
end
end

http_connect = Net::HTTP.new("taonix.net", 80)
resp, data = http_connect.get("/files/yp_bug2.xml", nil )

Document.parse_stream(data, Handler.new)
#Document.parse_stream((File.new "yp_bug2.xml"), Handler.new)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top