XML with non default encoding Topic is solved

Add-ons for Pale Moon and other applications
General discussion, compatibility, contributed extensions, themes, plugins, and more.

Moderators: FranklinDM, Lootyhoof

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

XML with non default encoding

Unread post by thosrtanner » 2017-10-14, 14:40

So there's an xml document I'm trying to download and display the contents of that starts off like this:

<?xml version="1.0" encoding="WINDOWS-1251"?>

How am I meant to deal with this? It seems that unless you tell `xmlhttprequest` the encoding, it downloads it as UTF8 and then you get all sorts of rubbish characters. i can get round this by setting `overrideMimeType('text/plain; charset=windows-1251')` in the xmlhttprequest but in general if I don't know what type the document is going to be (and usually I don't), it looks like I'd have to read the content type (as that appears to be correct in the header) and then re-download the document.

Surely there must be a simpler way of doing this? It's not like I can know the character encoding until I've downloaded the file

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: XML with non default encoding

Unread post by thosrtanner » 2017-10-14, 16:58

Damn. I can't edit the post now.

Found after some searching it doesn't like me doing responseType = text, which I was doing because, if you don't, then, for reasons known only to mozilla, the browser attempts to parse the returned text as xml even if you get an error back from the server. And then it drivels into the browser console.

I thught maybe it had been cleaned up but no such luck

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35591
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: XML with non default encoding

Unread post by Moonchild » 2017-10-15, 22:43

Sorry but if you do an "xmlhttprequest", did you expect the response to be parsed in any way other than XML by default?
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: XML with non default encoding

Unread post by thosrtanner » 2017-10-16, 07:13

in the case of the server saying there was a problem I don't expect it to attempt to attempt to parse the response text no. It seems rather a waste of time to say the least.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35591
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: XML with non default encoding

Unread post by Moonchild » 2017-10-16, 11:08

Since you're using a custom request, the server's response content (e.g. application server) may just as well be an XML. An error page's content can be anything the server wishes.

Any http server should also send back a content-type header along with their 40x or 50x pages, which you should check in your XHR dialogue with the server.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: XML with non default encoding

Unread post by thosrtanner » 2017-10-16, 11:42

After a lot of digging around I'm getting the results I want by requesting an 'arraybuffer' response and decode that using TextDecode.

Locked