* Encoding/decoding problems
@ 2011-07-28 8:18 Deniz Dogan
2011-07-28 9:01 ` Eli Zaretskii
0 siblings, 1 reply; 6+ messages in thread
From: Deniz Dogan @ 2011-07-28 8:18 UTC (permalink / raw)
To: help-gnu-emacs
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.
Any help appreciated!
Deniz
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding/decoding problems
2011-07-28 8:18 Encoding/decoding problems Deniz Dogan
@ 2011-07-28 9:01 ` Eli Zaretskii
2011-07-28 9:26 ` Deniz Dogan
0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2011-07-28 9:01 UTC (permalink / raw)
To: help-gnu-emacs
> 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).
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding/decoding problems
2011-07-28 9:01 ` Eli Zaretskii
@ 2011-07-28 9:26 ` Deniz Dogan
2011-07-28 10:01 ` Jambunathan K
2011-07-28 12:18 ` Eli Zaretskii
0 siblings, 2 replies; 6+ messages in thread
From: Deniz Dogan @ 2011-07-28 9:26 UTC (permalink / raw)
To: help-gnu-emacs
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".
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding/decoding problems
2011-07-28 9:26 ` Deniz Dogan
@ 2011-07-28 10:01 ` Jambunathan K
2011-07-28 12:18 ` Eli Zaretskii
1 sibling, 0 replies; 6+ messages in thread
From: Jambunathan K @ 2011-07-28 10:01 UTC (permalink / raw)
To: Deniz Dogan; +Cc: help-gnu-emacs
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
>
>
--
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding/decoding problems
2011-07-28 9:26 ` Deniz Dogan
2011-07-28 10:01 ` Jambunathan K
@ 2011-07-28 12:18 ` Eli Zaretskii
2011-07-28 12:23 ` Deniz Dogan
1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2011-07-28 12:18 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Thu, 28 Jul 2011 11:26:53 +0200
> From: Deniz Dogan <deniz@dogan.se>
>
> (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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Encoding/decoding problems
2011-07-28 12:18 ` Eli Zaretskii
@ 2011-07-28 12:23 ` Deniz Dogan
0 siblings, 0 replies; 6+ messages in thread
From: Deniz Dogan @ 2011-07-28 12:23 UTC (permalink / raw)
To: help-gnu-emacs
On 2011-07-28 14:18, Eli Zaretskii wrote:
>> Date: Thu, 28 Jul 2011 11:26:53 +0200
>> From: Deniz Dogan<deniz@dogan.se>
>>
>> (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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-07-28 12:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2011-07-28 12:18 ` Eli Zaretskii
2011-07-28 12:23 ` Deniz Dogan
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.