From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: Encoding/decoding problems Date: Thu, 28 Jul 2011 08:18:16 -0400 Message-ID: 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 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1311855507 24563 80.91.229.12 (28 Jul 2011 12:18:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 28 Jul 2011 12:18:27 +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:18:23 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 1QmPXj-0006X2-11 for geh-help-gnu-emacs@m.gmane.org; Thu, 28 Jul 2011 14:18:23 +0200 Original-Received: from localhost ([::1]:49718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmPXi-0003Sk-5w for geh-help-gnu-emacs@m.gmane.org; Thu, 28 Jul 2011 08:18:22 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:33011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmPXe-0003Sf-8N for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 08:18:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QmPXd-0005QW-4O for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 08:18:18 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]:41592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmPXc-0005QS-W3 for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 08:18:17 -0400 Original-Received: from eliz by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1QmPXc-0007lS-U8 for help-gnu-emacs@gnu.org; Thu, 28 Jul 2011 08:18:16 -0400 In-reply-to: <4E312B5D.6090600@dogan.se> (message from Deniz Dogan on Thu, 28 Jul 2011 11:26:53 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.10 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:81838 Archived-At: > 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.