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

Discussion in 'Ruby' started by Jesse P., Jan 4, 2008.

  1. Jesse P.

    Jesse P. Guest

    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
     
    Jesse P., Jan 4, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    0
    Views:
    8,203
  2. Damphyr
    Replies:
    2
    Views:
    156
    Damphyr
    Jul 16, 2003
  3. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    162
    Henrik Horneber
    Oct 12, 2004
  4. Phlip
    Replies:
    0
    Views:
    156
    Phlip
    Jan 15, 2008
  5. Petr Klima
    Replies:
    6
    Views:
    96
    Kouhei Sutou
    Nov 18, 2010
Loading...

Share This Page