View Full Version : Base64 decoding and converting to xml

06-20-2012, 10:19 AM
Hi frnds,

I am working on a task where I have to convert the Flex application to HTML5.

I am stuck at the very first step where the Flex application is provided a Base64 encoded string and application converts it to xml. (The Base64 encoded string is XML)

Following is the code used in Flex


This is the function in Flex used to convert Base64 encoded string to XML.

toXML(input:String, uncompress:Boolean = true):XML
var xml:XML;
var arr:ByteArray = Base64.decode(input);
if(uncompress) arr.uncompress();
arr.position = 0;
xml = new XML(arr.readUTFBytes(arr.length))
return xml;

I could find the base64Decode function in JQuery but how should I convert the decoded string to XML. I have been searching all over the net but could not find anything.

Any help is appreciated.

06-22-2012, 08:03 AM
I did some more research

It seems the xml is converted to ByteArray and then encoded to Base64. I can't change that because it has been developed and maintained by external developer.

In Flex
The received string is
1. unescaped
2. Base64 decoded
3. The received byte array is converted to XML.

Sample of code

I compared the Base64 decoded string in Flex and Javascript and there are few inconsistencies

The very first problem is Base64 decoding is presenting slightly different results for Flex and Javascript

I also tried converting the ByteArray to string using the following code in javascript but it is not outputting anything

:( :(