REXML::Document could not parse UTF-8 "<name>\302</name>"

J

Jesse P.

Hi all,

Im working with some UTF-8 data and basically if I run this:

require 'rexml/document'
data = "<name>\302</name>"
doc = REXML::Document.new(data)

I get an error that says I did not close the <name> tag:
REXML::parseException: #<REXML::parseException: No close tag for
["name"]>
/usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:26:in `parse'
/usr/lib/ruby/1.8/rexml/document.rb:190:in `build'
/usr/lib/ruby/1.8/rexml/document.rb:45:in `initialize'
(irb):48:in `new'
(irb):48:in `irb_binding'
/usr/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'
/usr/lib/ruby/1.8/irb/workspace.rb:52
....
No close tag for ["name"]
Line:
Position:
Last 80 unconsumed characters:

from /usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:89:in
`parse'
from /usr/lib/ruby/1.8/rexml/document.rb:190:in `build'
from /usr/lib/ruby/1.8/rexml/document.rb:45:in `initialize'
from (irb):48:in `new'
from (irb):48

The code only works if I use single quotes instead,
i.e.
doc = REXML::Document.new('<name>\302</name>')

But since data is a variable, I cant simply declare it with single
quotes.

Any ideas why REXML::Document doesnt parse properly? Or perhaps is
there a way around this? Maybe I can convert to some other character
encoding to avoid the problem...

Best regards,

Jesse
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top