Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Problem decoding UTF-8 strings from a web query
Pages: [1] Print
Author Topic: Problem decoding UTF-8 strings from a web query  (Read 414 times)
lucifer1
Newbie
*
Offline Offline

Posts: 3


View Profile
Problem decoding UTF-8 strings from a web query
« on: August 03, 2007, 04:22:40 AM »

I have implemented a placename lookup based on a web service

Request:
http://ws.geonames.org/findNearbyPlaceName?" "lat=50.46823299999998&lng=8.653849999999999&alt=1040
       
Answer:       
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
<geoname>
<name>Pohl Göns</name>
<lat>50.4666667</lat>
<lng>8.65</lng>
<geonameId>2852975</geonameId>
<countryCode>DE</countryCode>
<countryName>Germany</countryName>
<fcl>P</fcl>
<fcode>PPL</fcode>
<distance>0.3233816416273773</distance>
</geoname>
</geonames>

Here my REBOL code smippet extracting the information.
Code:
REBOL []
        url: to-url rejoin ["http://ws.geonames.org/findNearbyPlaceName?" "lat=50.46823299999998&lng=8.653849999999999&alt=1040"]
        citydata: read url
        parse citydata [thru "<name>" copy cityname to "</name>"]         
        write to-file rejoin [cityname ".txt"] citydata

Works fine until I use cityname to create a filename.
it ends up like this:  Pohl Göns.txt

Anyone have a solution to convert the special characters (ex. ä ö ü é è ß etc.)
so the filename shows up correct?

I use View 1.3 on Win XP SP2

Thanks
Logged
Brock
Newbie
*
Offline Offline

Posts: 14


View Profile
Re: Problem decoding UTF-8 strings from a web query
« Reply #1 on: August 12, 2007, 11:38:58 AM »

I personally have not worked with UTF-8  using Rebol, but maybe some of the scripts on Rebol.org will be helpful...
http://www.rebol.org/cgi-bin/cgiwrap/rebol/search.r?find=utf-8&form=yes
Logged
lucifer1
Newbie
*
Offline Offline

Posts: 3


View Profile
Solved: Problem decoding UTF-8 strings from a web query
« Reply #2 on: August 17, 2007, 01:45:26 AM »

Thanks for your hint.

I had tried UTF-8.r from the library before, but failed as i tried to convert the data after extracting the city name with parse.

I now converted the full data from the web query and this worked.

Code:
REBOL []

     do %hof.r
     do %utf-8.r
       
     url: to-url rejoin ["http://ws.geonames.org/findNearbyPlaceName?" "lat=50.46823299999998&lng=8.653849999999999&alt=1040"]
     x: read url
     y: decode 1 x
     y: x
     print y
     parse y [thru "<name>" copy name to "</name>"]
     write to-file rejoin [name ".txt"] y

This works fine.
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Problem decoding UTF-8 strings from a web query
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2008, 09:43:45 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2295 Posts in 593 Topics by 3763 Members
Latest Member: svolika

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc