Reading XML Feed - Encoding Issues

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Nellyvitadias
Posts: 6
Joined: Thu Mar 28, 2013 8:58 pm

Reading XML Feed - Encoding Issues

Post by Nellyvitadias » Wed May 15, 2013 4:44 pm

Hi All,

I'm new to LiveCode and rattling my brains as to why this fault is occurring.

The app I'm building pulls in an XML feed. If the feed has on the first line <?xml version="1.0" encoding="iso8859-1" ?> then it comes up with an error message:

"Failed to process preferences file with error: xmlerr, can't parse XML. Unsupported encoding iso8859-1"

If I copy the file to my local server and remove the first line <?xml version="1.0" encoding="iso8859-1" ?> then the app behaves as expected and correctly displays the XML fields.

I've googled for help and looked on forums that led me to believe I need to encode into UTF16. But after trying various solutions it isn't working for me, leading me to ask the experts.

Can someone please tell me where I'm going wrong.

Many thanks.

Neil

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Reading XML Feed - Encoding Issues

Post by Mark » Wed May 15, 2013 5:19 pm

Hi Neil,

Do you read the XML data from a URL? Assuming that you use LiveCode's XML external, you need something like this:

Code: Select all

put url "http://yourdomain.com/test.xml" into myXML
if the platform is "MacOS" then
  put isoToMac(myXML) into myXML
end if
put uniDecode(uniEncode(line 2 to -1 of myXML),"UTF8") into myXML
put "<?xml version=" & quote & "1.0" & quote && "encoding=" & quote & "UTF8" & quote && "?>" \
  & cr before myXML
You should now be able to parse the XML data in myXML.

Actually, I would think that you could also simply delete the first line, because the XML external also parses data without document data type definition. You could try that.

Let me know if this works.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Nellyvitadias
Posts: 6
Joined: Thu Mar 28, 2013 8:58 pm

Re: Reading XML Feed - Encoding Issues

Post by Nellyvitadias » Wed May 15, 2013 6:12 pm

Hi Mark,

Thank you very much for your help, your code worked superbly.

That's one problem I'll certainly remember!

Take care,

Neil

Post Reply