From: Jambunathan K <kjambunathan@gmail.com>
To: Deniz Dogan <deniz@dogan.se>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Encoding/decoding problems
Date: Thu, 28 Jul 2011 15:31:39 +0530 [thread overview]
Message-ID: <81tya6hgfw.fsf@gmail.com> (raw)
In-Reply-To: <4E312B5D.6090600@dogan.se> (Deniz Dogan's message of "Thu, 28 Jul 2011 11:26:53 +0200")
Deniz Dogan <deniz@dogan.se> writes:
> On 2011-07-28 11:01, Eli Zaretskii wrote:
>>> Date: Thu, 28 Jul 2011 10:18:04 +0200
>>> From: Deniz Dogan<deniz@dogan.se>
>>>
>>> I'm fetching an XML document that's uses iso-8859-1 coding with
>>> `url-retrieve' and then I parse it using `xml-parse-region'.
>>>
>>> After that, I get the parts of the document that I want and insert them
>>> into a buffer. However, the Swedish characters å, ä and ö are displayed
>>> as \345, \344 and \326 respectively.
>>>
>>> I've tried messing around with `encode-coding-region' and
>>> `decode-coding-region' but I'm really not sure what to do here.
>>
>> I suggest to start with describing a reproducible recipe for this
>> problem. Not sure if this forum is appropriate, perhaps emacs-devel
>> is a better place (as it sounds like you are describing a bug).
>>
>
> Here is the code to reproduce it:
>
> (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".
FWIW, this works as expected. Note the use of decode coding string.
(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
(decode-coding-string (nth 2 (nth 2 (nth 3 doc))) 'iso-8859-1)))))))
>
> I have no idea whether I should use `encode-region-string' or
> decode-region-string' or what. I'd doubt it's a bug to be honest,
> it's probably my lack of understanding that's causing this.
>
> Deniz
>
>
--
next prev parent reply other threads:[~2011-07-28 10:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-28 8:18 Encoding/decoding problems Deniz Dogan
2011-07-28 9:01 ` Eli Zaretskii
2011-07-28 9:26 ` Deniz Dogan
2011-07-28 10:01 ` Jambunathan K [this message]
2011-07-28 12:18 ` Eli Zaretskii
2011-07-28 12:23 ` Deniz Dogan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81tya6hgfw.fsf@gmail.com \
--to=kjambunathan@gmail.com \
--cc=deniz@dogan.se \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.