The better way than XML to return complex data from server to Rich Internet Applications client (ajax) or Flash

It's sure that XML is the good way for transferring data. However, in some applications, such as Flash, it is take a long time to write complex data ( in server ) as well as to read ( in client ) in XML form.
4 answers

Use flash and actionscript

After hours of search in the internet I figured out that flash in combination with actionscript 3 is able to provide mutli-select file dialogs. So I included a small flash file in my website to read the given input files and send them via a HTTP post request to a PHP file which moves the uploaded files iteratively to the specified destination location. In the constructor of the actionscript file I defined a file reference object and added some events that invoke certain methods automatically:<code>fileRef = new FileReferenceList();fileRef.addEventListener(Event.OPEN, fileRefListener_onOpen);fileRef.addEventListener(Event.CANCEL, fileRefListener_onCancel);fileRef.addEventListener(Event.SELECT, fileRefListener_onSelect);fileRef.addEventListener(ProgressEvent.PROGRESS, fileRefListener_onProgress);fileRef.addEventListener(Event.COMPLETE, fileRefListener_onComplete);</code>After that I specified a bunch of methods. The first one will be called if the user hits the “Upload-Files” button. It specifies the sort of files allowed to be uploaded (filter) and opens the upload dialog:private function browseClick(event:Event) {                var fileFilter:FileFilter = new FileFilter("Images", "*.jpg;*.jpeg;*.png");    fileRef.browse([fileFilter]);}Now I wrote the methods defined in the constructor that will be called automatically because of the event listeners. The most important is the “fileRefListener_onSelect”-method. It stores all file references in an array:public function fileRefListener_onSelect(event:Event) {        var fileRefList:FileReferenceList = FileReferenceList(event.target);    var list:Array = fileRefList.fileList;    var tempList = new Array();        for (var i:uint = 0; i < list.length; i++) {                                        tempList.push(list[i])    }        filesToUpload = filesToUpload.concat(tempList);}The other listener methods can be specified in the same way. They will be called if the file upload has started, ended or is still in progress (progress diagrams). In one last method I told the script to start the upload on the collection of filereferences . The variable “pathUploadScript” contains the URL of the PHP script:public function uploadFiles(event:Event){                filesUploaded = 0;        var item;    for(var i:Number = 0; i < filesToUpload.length; i++) {                item = filesToUpload[i];        item.addEventListener(Event.OPEN, fileRefListener_onOpen);        item.addEventListener(Event.CANCEL, fileRefListener_onCancel);                        item.addEventListener(ProgressEvent.PROGRESS, fileRefListener_onProgress);        item.addEventListener(Event.COMPLETE, fileRefListener_onComplete);        var url:URLRequest = new URLRequest(pathUploadScript);                if(!item.upload(url)) {            status_txt.htmlText = "Upload dialog failed to open.";        }    }}    The smallest version of this PHP file has to look similar to this:$uploadFile = $dir."/".$_FILES['Filedata']['name'];move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);It moves the file from the temporary upload directory to a location I specified in $uploadFile.

Taggings:

Microsoft aproach: Windows Communication Foundation

In general we have Binary data -> serialize XML -> SOAP -> HTTP [SERVER -> client] -> Soap -> XML -> Binary Data
With .Net framework 3.0 in WCF (Communication foundation) we can create direct pipe between client and server.
For more information and example please consult:
http://msdn.microsoft.com/en-us/library/ms751514.aspx

JSON - The better way than XML to return complex data from server to Rich Internet Applications client (ajax) or Flash

JSON, short for JavaScript Object Notation, is a lightweight computer data interchange format.

In some application, server has to return complex data to client, and it is better to use JSON since it is object and we can access its attribute easily like in object-oriented languages.

Taggings:

json - an alternative to xml

json can be seen as a light-weight alternative to XML.

http://www.json.org/index.html
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999.

It is just a very minimalistic generic serialization method of data-structures (objects, lists, or however you call it), so it can be used within (or between) virtually any language(s), but as it is a subset of JavaScript, it is especially suited for use in JavaScript applications and being much leaner (schlanker) than XML it is the interchange-format of choice for AJAX-applications,
which is the explicit main purpose of this format.

Taggings: