[Rbrainz-users] REXML::ParseException: Declarations can only occur in the doctype declaration. (MusicBrainz::Webservice::ResponseError)

Philipp Wolfer phw at rubyforge.org
Mon Aug 27 16:38:13 EDT 2007

2007/8/27, Armin Otto <arminotto at googlemail.com>:
> are you sure that rbrainz SENDS utf-8 strings ?
> I tried a query with some evil un-english characters and do not get any
> results.

RBrainz itself does not take care of the character encoding, you have
to pass properly encoded strings.

In your example you have to be careful, if you save that file as a
UTF-8 encoded file you'll double encode the characters (meaning each
of the two bytes of the UTF-8 character 'á' is treated as a Latin1
character and get's converted into it's UTF-8 representation. You then
end up with four bytes representing two UTF-8 characters.

So either you save the file as UTF-8 without the iconv call or you
save the file as ISO-8859-1 with the conversion in the code. Both
works for me.

There are several reasons why RBrainz has no special UTF-8 support:
1. Ruby has currently bad support for UTF-8 (will get better in Ruby
1.9), you only can set the encoding globally. But applications using
Rbrainz may use other encodings.
2. You can't automatically convert strings passed to RBrainz to UTF-8,
since RBrainz doesn't know anything about the encoding the application
3. RBrainz does not need $KCODE set to UTF-8, since it does not use
any critical string operations (e.g. String#size or substring#slice)

So the only way is for the application using RBrainz to take care of
the encoding. But if you want to display international artists you
will most likely end up using UTF-8 in your application anyway :-)

I will add some information about that topic to the RBrainz
documentaion since it is currently not clear.

Philipp Wolfer

More information about the Rbrainz-users mailing list