From: "Jesse P." Date: 2008-01-06T22:30:00+09:00 Subject: Re: Regexp for matching UTF-8 characters without close tag Thanks Tiziano :) On Jan 6, 3:56 am, Tiziano Merzi wrote: > Jesse P. wrote: > > Hi Tiziano, > > > My apologies. It seems that I have oversimplied the problem due to my > > lack of understanding for UTF-8. > > > The actual string is an xml file I obtained from flickr at > >http://api.flickr.com/services/rest/?method=flickr.people.getInfo&api... > > You have a broken utf-8 docoment (a read the Matz reply) > > I see two solutions: > > a) > > require 'rexml/document' > require 'iconv' > > data = your xml document > data = Iconv.conv("UTF-8","ISO-8859-1",data) > doc = REXML::Document.new(data) > > you must convert the data of doc from utf-8 to iso befor use it > > username = Iconv.conv("ISO-8859-1","UTF-8",doc. ) > > b) change the encoding of the xml > > require 'rexml/document' > > data = your xml document > data = data.gsub(/encoding="utf-8"/i, 'encoding="iso-8859-1"') > doc = REXML::Document.new(data) > > Anyway a) and b) don't work if the document contains valid utf-8 chars > not in ascii-7 (for example latin letters è, ò, etc.) > > -- > Posted viahttp://www.ruby-forum.com/.