Index: branches/prototype-v0/zoo-project/zoo-api/js/ZOO-api.js
===================================================================
--- branches/prototype-v0/zoo-project/zoo-api/js/ZOO-api.js	(revision 874)
+++ branches/prototype-v0/zoo-project/zoo-api/js/ZOO-api.js	(revision 879)
@@ -3678,8 +3678,10 @@
 	}
 	var builder = this.parseData[data.localName().toLowerCase()];
-	if (builder)
+	if (builder){
 	  res.push(builder.apply(this,[data]));
+	}
 	else
 	  res.push(null);
+	data=null;
       }
       return res.length>1?res:res[0];
@@ -3740,6 +3742,8 @@
      * {Object} A WPS reference response.
      */
-    'reference': function(node) {
-      var result = {type:'reference',value:node.@href};
+    'reference': function(lnode) {
+      var lhref=lnode.@href;
+      var lmimeType=lnode.@mimeType;
+      var result = {type:'reference',value:lhref.toXMLString(),mimeType:lmimeType.toXMLString()};
       return result;
     }
@@ -6168,7 +6172,7 @@
     body = body.toXMLString();
     var headers=['Content-Type: text/xml; charset=UTF-8'];
-      if(arguments.length>2){
-	headers[headers.length]=arguments[2];
-      }
+    if(arguments.length>2){
+      headers[headers.length]=arguments[2];
+    }
     var response = ZOO.Request.Post(this.url,body,headers);
     return response;
@@ -6187,5 +6191,10 @@
      */
     'ResponseDocument': function(identifier,obj) {
-      var output = new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'"><wps:ResponseDocument><wps:Output'+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+(obj["asReference"]?' asReference="'+obj["asReference"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:Output></wps:ResponseDocument></wps:ResponseForm>');
+      var output = new XML('<wps:Output xmlns:wps="'+this.namespaces['wps']+'" '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+(obj["asReference"]?' asReference="'+obj["asReference"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:Output>');
+      output = output.toXMLString();
+      return output;
+    },
+    'RawDataOutput': function(identifier,obj) {
+      var output = new XML('<wps:RawDataOutput xmlns:wps="'+this.namespaces['wps']+'" '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:RawDataOutput>');
       if (obj.encoding)
         output.*::Data.*::ComplexData.@encoding = obj.encoding;
@@ -6194,13 +6203,4 @@
       output = output.toXMLString();
       return output;
-    },
-    'RawDataOutput': function(identifier,obj) {
-      var output = new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'"><wps:RawDataOutput '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:RawDataOutput></wps:ResponseForm>');
-      if (obj.encoding)
-        output.*::Data.*::ComplexData.@encoding = obj.encoding;
-      if (obj.schema)
-        output.*::Data.*::ComplexData.@schema = obj.schema;
-      output = output.toXMLString();
-      return output;
     }
 
@@ -6223,9 +6223,9 @@
      */
     'complex': function(identifier,data) {
-      var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>');
+      var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData '+(data.mimeType?'mimeType="'+data.mimeType+'"':"")+'><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>');
       if(data.xlink)
-	input.*::Reference.@mimeType = data.mimetype ? data.mimetype : 'application/json';
+        input.*::Reference.@mimeType = data.mimetype ? data.mimetype : 'application/json';
       else
-	input.*::Data.*::ComplexData.@mimeType = data.mimetype ? data.mimetype : 'application/json';
+        input.*::Data.*::ComplexData.@mimeType = data.mimetype ? data.mimetype : 'application/json';
       if (data.encoding)
         input.*::Data.*::ComplexData.@encoding = data.encoding;
@@ -6233,5 +6233,8 @@
         input.*::Data.*::ComplexData.@schema = data.schema;
       input = input.toXMLString();
-      return input;
+      if(data.value)
+        return (('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData '+(data.mimeType?'mimeType="'+data.mimeType+'"':"")+'><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>'));
+      else
+        return input;
     },
     /**
@@ -6261,25 +6264,24 @@
      */
     'literal': function(identifier,data) {
-	if(data && !eval(data["isArray"])){
-	    var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>');
-      if (data.type)
-        input.*::Data.*::LiteralData.@dataType = data.type;
-      if (data.uom)
-        input.*::Data.*::LiteralData.@uom = data.uom;
-      input = input.toXMLString();
-      return input;
-	}else if(data){
-	    var inputf="";
-	    for(i=0;i<parseInt(data["length"]);i++){
-		var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value[i]+'</wps:LiteralData></wps:Data></wps:Input>');
-		if (data.type)
-		    input.*::Data.*::LiteralData.@dataType = data.type;
-		if (data.uom)
-		    input.*::Data.*::LiteralData.@uom = data.uom;
-		inputf += input.toXMLString();
-	    }
-	    return inputf;
+      if(data && !eval(data["isArray"])){
+        var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>');
+        if (data.type)
+	  input.*::Data.*::LiteralData.@dataType = data.type;
+        if (data.uom)
+	  input.*::Data.*::LiteralData.@uom = data.uom;
+        input = input.toXMLString();
+        return input;
+      }else if(data){
+        var inputf="";
+        for(i=0;i<parseInt(data["length"]);i++){
+	  var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value[i]+'</wps:LiteralData></wps:Data></wps:Input>');
+	  if (data.type)
+	    input.*::Data.*::LiteralData.@dataType = data.type;
+	  if (data.uom)
+	    input.*::Data.*::LiteralData.@uom = data.uom;
+	  inputf += input.toXMLString();
 	}
-	
+        return inputf;
+      }	
     }
   },
@@ -6310,11 +6312,28 @@
 
   buildDataOutputsNode:function(outputs){
-    var data, builder, outputsArray=[];
+    var data, builder, outputsArray=[[],[]];
     for (var attr in outputs) {
       data = outputs[attr];
       builder = this.buildOutput[data.type];
-      outputsArray.push(builder.apply(this,[attr,data]));
-    }
-    return outputsArray.join('\n');
+      if(data.type=="ResponseDocument")
+        outputsArray[0].push(builder.apply(this,[attr,data]));
+      else
+        outputsArray[1].push(builder.apply(this,[attr,data]));	    
+    }
+    var responseDocuments=(outputsArray[0].length>0?
+			   new XML('<wps:ResponseDocument xmlns:wps="'+this.namespaces['wps']+'">'+
+				   outputsArray[0].join('\n')+
+				   '</wps:ResponseDocument>')
+			   :
+			   null);
+    var rawDataOutputs=(outputsArray[1].length>0?
+			outputsArray[1].join('\n')
+			:
+			null);
+    var res=new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'">'+
+		    (responseDocuments!=null?responseDocuments.toXMLString():"")+
+		    (rawDataOutputs!=null?rawDataOutputs:"")+
+		    '</wps:ResponseForm>');
+    return res.toXMLString();
   },
 
