From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Deniz Dogan Newsgroups: gmane.emacs.help Subject: Re: Encoding/decoding problems Date: Thu, 28 Jul 2011 14:23:04 +0200 Message-ID: <4E3154A8.8010604@dogan.se> References: <4E311B3C.7040301@dogan.se> <4E312B5D.6090600@dogan.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1311855859 26824 80.91.229.12 (28 Jul 2011 12:24:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 28 Jul 2011 12:24:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 28 14:24:15 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QmPdO-0000dz-45 for geh-help-gnu-emacs@m.gmane.org; Thu, 28 Jul 2011 14:24:14 +0200 Original-Received: from localhost ([::1]:33605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmPdN-00051C-Gv for geh-help-gnu-emacs@m.gmane.org; Thu, 28 Jul 2011 08:24:13 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:34162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmPdJ-0004xs-4F for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 08:24:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QmPdI-0006UX-0o for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 08:24:09 -0400 Original-Received: from ch-smtp05.sth.basefarm.net ([80.76.153.6]:53029) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmPdH-0006US-Mt for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 08:24:07 -0400 Original-Received: from c80-216-105-155.bredband.comhem.se ([80.216.105.155]:63937 helo=[192.168.0.10]) by ch-smtp05.sth.basefarm.net with esmtp (Exim 4.76) (envelope-from ) id 1QmPcY-0001X6-GX for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 14:23:24 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: X-Originating-IP: 80.216.105.155 X-Scan-Result: No virus found in message 1QmPcY-0001X6-GX. X-Scan-Signature: ch-smtp05.sth.basefarm.net 1QmPcY-0001X6-GX 1ac8afd9b9fc4b843359f457adcb616a X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.76.153.6 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81839 Archived-At: On 2011-07-28 14:18, Eli Zaretskii wrote: >> Date: Thu, 28 Jul 2011 11:26:53 +0200 >> From: Deniz Dogan >> >> (defun fetch-and-show () >> (interactive) >> (let* ((old-buffer (current-buffer)) >> (url "http://dogan.se/sites/default/files/example.xml") >> (buffer (url-retrieve-synchronously url))) >> (with-current-buffer buffer >> (let ((doc (car (xml-parse-region (point-min) (point-max))))) >> (with-current-buffer old-buffer >> (insert >> (nth 2 (nth 2 (nth 3 doc))))))))) >> >> The XML file is encoded in iso-8859-1 with a bunch of Swedish characters >> here and there. The buffer I'm testing this with is *scratch* with >> utf-8-unix. It should insert "hallå" but inserts "hall\345". >> >> I have no idea whether I should use `encode-region-string' or >> `decode-region-string' or what. > > "Encoding" means converting Emacs's internal representation into an > external representation you want to send to a disk file or another > program. "Decoding" is the opposite conversion: from an external > representation that you found in a disk file or received from a > network socket to the internal representation Emacs uses in its buffer > and string objects. > > So you want "decode-" functions, in this case decode-coding-string, > since you've got the external representation in a string. > Thanks for the explanation and thank you to Jambunathan for the help. It appeared that I had simply done the decoding at the wrong stage of the processing somehow (the real example is a lot larger). Again, thanks Deniz