]> git.mjollnir.org Git - moodle.git/commitdiff
web service MDL-12886 return value fix for REST server
authorjerome <jerome>
Wed, 25 Feb 2009 04:52:17 +0000 (04:52 +0000)
committerjerome <jerome>
Wed, 25 Feb 2009 04:52:17 +0000 (04:52 +0000)
webservice/lib.php
webservice/rest/locallib.php
webservice/rest/testclient/getgroup.php
webservice/rest/testclient/getusers.php
webservice/rest/testclient/index.php [moved from webservice/rest/testclient/php_curl_rest_client.php with 93% similarity]
webservice/rest/testclient/lib.php

index 3e1153701acf664668abc6d5b64abee66078f255..dc213799c76511402a7fb2ca216962a7cd03012d 100644 (file)
@@ -138,186 +138,179 @@ final class webservice_lib {
 
         foreach($reflection->getMethods() as $method){
 
-            if ($method->getName()!="get_function_webservice_description"
-                && $method->getName()!="get_descriptions" ) {
-                $docBlock = $method->getDocComment();
+            $docBlock = $method->getDocComment();
 
+            //retrieve the return and add it into the description if not array|object
+            preg_match_all('/@return\s+(\w+)\s+((?:\$)?\w+)/', $docBlock, $returnmatches);
 
-                //retrieve the return and add it into the description if not array|object
-                preg_match_all('/@return\s+(\w+)\s+((?:\$)?\w+)/', $docBlock, $returnmatches);
+            //retrieve the subparam and subreturn
+            preg_match_all('/\s*\*\s*@(subparam|subreturn)\s+(\w+)\s+(\$\w+(?::\w+|->\w+)+)((?:\s+(?:optional|required|multiple))*)/', $docBlock, $matches);
 
-                //retrieve the subparam and subreturn
-                preg_match_all('/\s*\*\s*@(subparam|subreturn)\s+(\w+)\s+(\$\w+(?::\w+|->\w+)+)((?:\s+(?:optional|required|multiple))*)/', $docBlock, $matches);
+            for($i=0;$i<sizeof($matches[1]);$i++){
+                //   var_dump(strpos("optional", $matches[4][$i]));
+                switch ($matches[1][$i]) {
+                    case "subparam":
+                        if (strpos($matches[4][$i], "optional")!==false) {
+                            $descriptiontype = "optional";
+                        } else {
+                            $descriptiontype = "params" ;
+                        }
+                        break;
+                    case "subreturn":
+                        $descriptiontype = "return";
+                        break;
+                }
 
-                for($i=0;$i<sizeof($matches[1]);$i++){
-                    //   var_dump(strpos("optional", $matches[4][$i]));
-                    switch ($matches[1][$i]) {
-                        case "subparam":
-                            if (strpos($matches[4][$i], "optional")!==false) {
-                                $descriptiontype = "optional";
-                            } else {
-                                $descriptiontype = "params" ;
-                            }
-                            break;
-                        case "subreturn":
-                            $descriptiontype = "return";
-                            break;
-                    }
+                if (empty($description[$method->getName()])) {
+                    $description[$method->getName()] = array();
+                }
+
+                if (strpos($returnmatches[1][0] ,"object")===false && strpos($returnmatches[1][0],"array")===false) {
+                    $description[$method->getName()]['return'] = array($returnmatches[2][0] => $returnmatches[1][0]);
+                }
+
+                if ($matches[1][$i] == "subparam" || $matches[1][$i] == "subreturn") {
 
-                    if (empty($description[$method->getName()])) {
-                        $description[$method->getName()] = array();
+
+                    ///algorythm parts
+                    ///1. We compare the string to the description array
+                    ///   When we find a attribut that is not in the description, we retrieve all the rest of the string
+                    ///2. We create the missing part of the description array, starting from the end of the rest of the string
+                    ///3. We add the missing part to the description array
+
+                    ///Part 1.
+
+
+                    ///construct the description array
+                    if (strpos($matches[3][$i], "->")===false && strpos($matches[3][$i], ":")===false) {
+                        //no separator
+                        $otherparam = $matches[3][$i];
                     }
+                    else if (strpos($matches[3][$i], "->")===false || (strpos($matches[3][$i], ":")!==false && (strpos($matches[3][$i], ":") < strpos($matches[3][$i], "->")))) {
+                        $separator = ":";
+                        $separatorsize=1;
 
-                    if (strpos($returnmatches[1][0] ,"object")===false && strpos($returnmatches[1][0],"array")===false) {
-                        $description[$method->getName()]['return'] = array($returnmatches[2][0] => $returnmatches[1][0]);
+                    } else {
+                        $separator = "->";
+                        $separatorsize=2;
                     }
 
-                    if ($matches[1][$i] == "subparam" || $matches[1][$i] == "subreturn") {
+                    $param = substr($matches[3][$i],1,strpos($matches[3][$i], $separator)-1);
 
+                    $otherparam = substr($matches[3][$i],strpos($matches[3][$i], $separator)+$separatorsize);
+                    $parsingdesc = $description[$method->getName()];
 
-                        ///algorythm parts
-                        ///1. We compare the string to the description array
-                        ///   When we find a attribut that is not in the description, we retrieve all the rest of the string
-                        ///2. We create the missing part of the description array, starting from the end of the rest of the string
-                        ///3. We add the missing part to the description array
+                    if (!empty($parsingdesc) && array_key_exists($descriptiontype, $parsingdesc)){
+                        $parsingdesc = $parsingdesc[$descriptiontype];
+                    }
+                    $descriptionpath=array();
 
-                        ///Part 1.
+                    $creationfinished = false;
+                    unset($type);
 
+                    while(!$creationfinished && (strpos($otherparam, ":") || strpos($otherparam, "->"))) {
+                        if (strpos($otherparam, "->")===false || (strpos($otherparam, ":")!==false && (strpos($otherparam, ":") < strpos($otherparam, "->")))) {
+                            $type = $separator;
 
-                        ///construct the description array
-                        if (strpos($matches[3][$i], "->")===false && strpos($matches[3][$i], ":")===false) {
-                            //no separator
-                            $otherparam = $matches[3][$i];
-                        }
-                        else if (strpos($matches[3][$i], "->")===false || (strpos($matches[3][$i], ":")!==false && (strpos($matches[3][$i], ":") < strpos($matches[3][$i], "->")))) {
                             $separator = ":";
                             $separatorsize=1;
-
                         } else {
+                            $type = $separator;
                             $separator = "->";
                             $separatorsize=2;
                         }
 
-                        $param = substr($matches[3][$i],1,strpos($matches[3][$i], $separator)-1);
+                        $param = substr($otherparam,0,strpos($otherparam, $separator));
 
-                        $otherparam = substr($matches[3][$i],strpos($matches[3][$i], $separator)+$separatorsize);
-                        $parsingdesc = $description[$method->getName()];
-                        
-                        if (!empty($parsingdesc) && array_key_exists($descriptiontype, $parsingdesc)){
-                            $parsingdesc = $parsingdesc[$descriptiontype];
-                        }
-                        $descriptionpath=array();
+                        $otherparam = substr($otherparam,strpos($otherparam, $separator)+$separatorsize);
 
-                        $creationfinished = false;
-                        unset($type);
 
-                        while(!$creationfinished && (strpos($otherparam, ":") || strpos($otherparam, "->"))) {
-                            if (strpos($otherparam, "->")===false || (strpos($otherparam, ":")!==false && (strpos($otherparam, ":") < strpos($otherparam, "->")))) {
-                                $type = $separator;
-
-                                $separator = ":";
-                                $separatorsize=1;
-                            } else {
-                                $type = $separator;
-                                $separator = "->";
-                                $separatorsize=2;
-                            }
-
-                            $param = substr($otherparam,0,strpos($otherparam, $separator));
-
-                            $otherparam = substr($otherparam,strpos($otherparam, $separator)+$separatorsize);
+                        if ($type==":") {
+                            if (!array_key_exists('multiple:'.$param, $parsingdesc)){
 
+                                $desctoadd = webservice_lib::create_end_of_description(":".$param.$separator.$otherparam, $matches[2][$i]);
 
-                            if ($type==":") {
-                                if (!array_key_exists('multiple:'.$param, $parsingdesc)){
-
-                                    $desctoadd = webservice_lib::create_end_of_description(":".$param.$separator.$otherparam, $matches[2][$i]);
-
-                                    if(empty($descriptionpath) ) {
-                                        if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) {
-                                            $desctoadd = array($descriptiontype => $desctoadd);
-                                        }
-                                        $paramtoadd = $descriptiontype;
-                                    } else {
-                                        $paramtoadd = 'multiple:'.$param;
+                                if(empty($descriptionpath) ) {
+                                    if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) {
+                                        $desctoadd = array($descriptiontype => $desctoadd);
                                     }
-                                    webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath);
-                                    $creationfinished = true;
+                                    $paramtoadd = $descriptiontype;
                                 } else {
-                                    if(empty($descriptionpath)) {
-                                        $descriptionpath[] = $descriptiontype;
-                                    }
-                                    $descriptionpath[] = 'multiple:'.$param;
-                                    $parsingdesc = $parsingdesc['multiple:'.$param];
+                                    $paramtoadd = 'multiple:'.$param;
                                 }
+                                webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath);
+                                $creationfinished = true;
                             } else {
-                                if (!array_key_exists($param, $parsingdesc)){
-
-                                    $desctoadd = webservice_lib::create_end_of_description("->".$param.$separator.$otherparam, $matches[2][$i]);
-
-                                    if(empty($descriptionpath)) {
-
-                                        if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) {
-                                            $desctoadd = array($descriptiontype => $desctoadd);
-                                        }
-                                        $paramtoadd = $descriptiontype;
-
-                                    } else {
-                                        $paramtoadd = $param;
-                                    }
-                                    webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath);
-
-                                    $creationfinished = true;
-                                } else {
-                                    if(empty($descriptionpath)) {
-                                        $descriptionpath[] = $descriptiontype;
-                                    }
-                                    $descriptionpath[] = $param;
-                                    $parsingdesc = $parsingdesc[$param];
+                                if(empty($descriptionpath)) {
+                                    $descriptionpath[] = $descriptiontype;
                                 }
+                                $descriptionpath[] = 'multiple:'.$param;
+                                $parsingdesc = $parsingdesc['multiple:'.$param];
                             }
+                        } else {
+                            if (!array_key_exists($param, $parsingdesc)){
 
-                        }
-
-                        if (!$creationfinished) {
-
-                            if (!empty($type) && $type==":") {
-
-                                $desctoadd = webservice_lib::create_end_of_description($separator.$otherparam, $matches[2][$i]);
+                                $desctoadd = webservice_lib::create_end_of_description("->".$param.$separator.$otherparam, $matches[2][$i]);
 
                                 if(empty($descriptionpath)) {
+
                                     if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) {
                                         $desctoadd = array($descriptiontype => $desctoadd);
                                     }
                                     $paramtoadd = $descriptiontype;
+
                                 } else {
-                                    $paramtoadd = 'multiple:'.$param;
+                                    $paramtoadd = $param;
                                 }
-
                                 webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath);
 
+                                $creationfinished = true;
                             } else {
-                                $desctoadd = webservice_lib::create_end_of_description($separator.$otherparam, $matches[2][$i]);
                                 if(empty($descriptionpath)) {
+                                    $descriptionpath[] = $descriptiontype;
+                                }
+                                $descriptionpath[] = $param;
+                                $parsingdesc = $parsingdesc[$param];
+                            }
+                        }
 
-                                    if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) {
-                                        $desctoadd = array($descriptiontype => $desctoadd);
-                                    }
-                                    $paramtoadd = $descriptiontype;
+                    }
 
-                                } else {
-                                    $paramtoadd = $param;
+                    if (!$creationfinished) {
+
+                        if (!empty($type) && $type==":") {
 
+                            $desctoadd = webservice_lib::create_end_of_description($separator.$otherparam, $matches[2][$i]);
+
+                            if(empty($descriptionpath)) {
+                                if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) {
+                                    $desctoadd = array($descriptiontype => $desctoadd);
                                 }
-                                webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath);
+                                $paramtoadd = $descriptiontype;
+                            } else {
+                                $paramtoadd = 'multiple:'.$param;
+                            }
+
+                            webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath);
+
+                        } else {
+                            $desctoadd = webservice_lib::create_end_of_description($separator.$otherparam, $matches[2][$i]);
+                            if(empty($descriptionpath)) {
 
+                                if (empty($description[$method->getName()]) || !array_key_exists($descriptiontype, $description[$method->getName()])) {
+                                    $desctoadd = array($descriptiontype => $desctoadd);
+                                }
+                                $paramtoadd = $descriptiontype;
+
+                            } else {
+                                $paramtoadd = $param;
                             }
+                            webservice_lib::add_end_of_description($paramtoadd, $desctoadd, $description[$method->getName()], $descriptionpath);
                         }
                     }
                 }
             }
         }
-
         return $description;
     }
 
index 27125aa7f1b19dfa9f46d3d0a5fa209c87e604ca..8c17ffeb24d4c7e3a2bf39e36b9c1b0ed11b39b6 100644 (file)
@@ -93,7 +93,14 @@ function call_moodle_function ($rest_arguments) {
     }
 
     ///Transform result into xml in order to send the REST response
-    $return =  mdl_conn_rest_object_to_xml ($res,key($description[$functionname]['return']));
+    $key = key($description[$functionname]['return']);
+
+    if (strpos($key,":")!==false) {
+        $key = substr($key, strpos($key,":")+1);
+    } else {
+        $key = 'return';
+    }
+    $return =  mdl_conn_rest_object_to_xml ($res,$key);
 
     return "<Result>$return</Result>";
 }
index 1578202c2fa02b0c92c23ff2203a33c25bfcb8cf..3a3a9003ade6cee1e04c9f9f214b62c49c5f6f9a 100644 (file)
@@ -53,7 +53,7 @@ if ($groupid) {
 
     $res = basicxml_xml_to_object($out);
 
-       show_object($res->group);
+       show_object($res->return);
 
     show_xml ($out);
 } else {
index cb4c35e4d5a756f2f879962a7323cb3ad6b224fe..4e62b9a6dc9e569edc4233bb2f8a9999fc2de1ea 100644 (file)
@@ -32,9 +32,6 @@ start_interface("List of Users");
 if ($search) {
     $data['search'] = $search;
 
-    var_dump($CFG->serverurl.'/user/tmp_get_users');
-
-
     //we are asking for a token
     $connectiondata['username'] = 'wsuser';
     $connectiondata['password'] = 'wspassword';
similarity index 93%
rename from webservice/rest/testclient/php_curl_rest_client.php
rename to webservice/rest/testclient/index.php
index 29c024a536944ddc3cbc39f64d20acb5b626f506..be0dca44d2d467701a0be0cec4c719908e4ac33b 100644 (file)
@@ -21,7 +21,8 @@ $links = array( array('USERS'),
                 array('updateuser.php','update_user()'),
                 array('GROUPS'),
                 array('creategroup.php','create_group()'),
-                array('addgroupmember.php', 'add_groupmember()'));
+                array('addgroupmember.php', 'add_groupmember()'),
+                array('getgroup.php', 'get_group()'));
 
 echo '<ul>';
 foreach ($links as $link) {
index 8d99273285f167ccd6b5e9101be69d6111e377c4..47f5a883e88f2a376c79d344f625809d7d4217fa 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /**
  * Created on 10/17/2008
- * 
+ *
  * Rest Test Client Suport Library
  *
  * @author David Castro Garcia
  * starts the interface
  */
 function start_interface ($title="&nbsp;") {
-       $title2 = ($title)?$title:"&nbsp;";
-       echo '<html><head>';
-       echo "<title>Moodle Webservice Rest Test Client</title>";
-       echo '<link rel="stylesheet" href="style.css" type="text/css">';
-       echo '</head><body>';
-       echo '<div class="head"><h1>Moodle Webservice Rest Test Client</h1>';
-       echo "<h3>$title2</h3>";
-       echo '</div>';
-       echo '<div class="content">';
-       if ($title) echo '<p class="return"><a href="index.php"><img src="return.gif" border="0"/></a></p>';
+    $title2 = ($title)?$title:"&nbsp;";
+    echo '<html><head>';
+    echo "<title>Moodle Webservice Rest Test Client</title>";
+    echo '<link rel="stylesheet" href="style.css" type="text/css">';
+    echo '</head><body>';
+    echo '<div class="head"><h1>Moodle Webservice Rest Test Client</h1>';
+    echo "<h3>$title2</h3>";
+    echo '</div>';
+    echo '<div class="content">';
+    if ($title) echo '<p class="return"><a href="index.php"><img src="return.gif" border="0"/></a></p>';
 }
 
 /**
  * end interface
- * 
+ *
  * @param bool $ret=true: show return button
  */
 function end_interface ($ret = true) {
-       if ($ret) echo '<p class="return"><a href="index.php"><img src="return.gif" border="0"/></a></p>';
-       echo '</div>';
-       echo '<div class="footer">Created by David Castro i Ferran Recio for Moodle Webservices</div>';
-       echo '</body></html>';
+    if ($ret) echo '<p class="return"><a href="index.php"><img src="return.gif" border="0"/></a></p>';
+    echo '</div>';
+    echo '<div class="footer">Created by David Castro i Ferran Recio for Moodle Webservices</div>';
+    echo '</body></html>';
 }
 
 /**
  * print XML div area
- * 
+ *
  * @param string $xml
- * 
+ *
  */
 function show_xml ($xml) {
-       echo '<div class="xmlshow">';
-       echo '<a onClick="document.getElementById(\'toogleme\').style.display = ' .
-                       '(document.getElementById(\'toogleme\').style.display!=\'none\')?\'none\':\'\';">Hide/Show XML</a>';
-       echo "<div style=\"display:none;\" id=\"toogleme\">";
-       echo '<pre>';echo htmlentities($xml);echo '</pre>';
-       echo "</div>";
-       echo "</div>";
+    echo '<div class="xmlshow">';
+    echo '<a onClick="document.getElementById(\'toogleme\').style.display = ' .
+            '(document.getElementById(\'toogleme\').style.display!=\'none\')?\'none\':\'\';">Hide/Show XML</a>';
+    echo "<div style=\"display:none;\" id=\"toogleme\">";
+    echo '<pre>';echo htmlentities($xml);echo '</pre>';
+    echo "</div>";
+    echo "</div>";
 }
 
 /**
  * format post data
  */
 function format_postdata ($data) {
-       $o="";
-       foreach ($data as $k=>$v) {
-               $o.= "$k=".rawurlencode($v)."&";
-       }
-       $post_data=substr($o,0,-1);
-       return $post_data;
+    $o="";
+    foreach ($data as $k=>$v) {
+        $o.= "$k=".rawurlencode($v)."&";
+    }
+    $post_data=substr($o,0,-1);
+    return $post_data;
 }
 
 /**
  * shows an object in list format
- * 
+ *
  * @param mixed $obj
  * @param integer $cols: number of colums
  * @ string string $check=false: if this attribute is not present, the $obj is ans error
- * 
+ *
  */
 function show_object ($obj,$cols=1,$check=false) {
-       if (!is_array($obj)) $obj = array($obj);
-       echo '<ul class="results">';
-       foreach ($obj as $r) {
-               
-               if ($check && (!isset($r->$check) || $r->$check==-1)) {
-                       echo '<li class="error">';
-                       echo "EMPTY ROW!";
-               } else {
-                       if (is_object($r)) {
-                               echo '<li class="element">';
-                               $text = array();
-                               $parts = get_object_vars($r);
-                               $num = 1;
-                               $currline = '';
-                               foreach ($parts as $key => $val) {
-                                       $currline.= "<span class=\"resultval\"><b>$key:</b> <i>$val</i></span>, ";
-                                       if ($num >= $cols) {
-                                               $currline=substr($currline,0,-2);
-                                               $text[] = $currline;
-                                               $currline = '';
-                                               $num = 0;
-                                       }
-                                       $num++;
-                               }
-                               echo implode('<br/>',$text);
-                       } else {
-                               if ($r==-1 || !$r) {
-                                       echo '<li class="error">';
-                                       echo "EMPTY ROW!";
-                               } else {
-                                       echo '<li class="element">';
-                                       echo "<span class=\"resultval\"><b>Returned Value:</b> <i>$r</i></span>";
-                               }
-                       }
-               }
-               echo '</li>';
-       }
-       echo '</ul>';
+    if (!is_array($obj)) $obj = array($obj);
+    echo '<ul class="results">';
+    foreach ($obj as $r) {
+
+        if ($check && (!isset($r->$check) || $r->$check==-1)) {
+            echo '<li class="error">';
+            echo "EMPTY ROW!";
+        } else {
+            if (is_object($r)) {
+                echo '<li class="element">';
+                $text = array();
+                $parts = get_object_vars($r);
+                $num = 1;
+                $currline = '';
+                foreach ($parts as $key => $val) {
+                    $currline.= "<span class=\"resultval\"><b>$key:</b> <i>$val</i></span>, ";
+                    if ($num >= $cols) {
+                        $currline=substr($currline,0,-2);
+                        $text[] = $currline;
+                        $currline = '';
+                        $num = 0;
+                    }
+                    $num++;
+                }
+                echo implode('<br/>',$text);
+            } else {
+                if ($r==-1 || !$r) {
+                    echo '<li class="error">';
+                    echo "EMPTY ROW!";
+                } else {
+                    echo '<li class="element">';
+                    echo "<span class=\"resultval\"><b>Returned Value:</b> <i>$r</i></span>";
+                }
+            }
+        }
+        echo '</li>';
+    }
+    echo '</ul>';
 }
 
 
@@ -121,104 +121,106 @@ function show_object ($obj,$cols=1,$check=false) {
 
 /**
  * convert a simple xml into php object
- * 
+ *
  * @author ferran recio
- * 
+ *
  * @param String $xml
- * 
+ *
  * @return mixed
  */
 function basicxml_xml_to_object ($xml) {
-       $xml=utf8_encode($xml);
-       
-       //create the parser
-       $parser = xml_parser_create ();
-       xml_set_default_handler ($parser,'basicxml_xml_to_object_aux');
-       
-       $values = array();
-       $index = array();
-       xml_parse_into_struct($parser,$xml,$values,$index);
-       
-       //print_object($values);
-       //print_object($index);
-       
-       //just simplexml tag (disabled)
-       //if (strtolower($values[0]['tag']) != 'basicxml') return false;
-       //if (strtolower($values[count($values)-1]['tag']) != 'basicxml') return false;
-       
-       $res = basicxml_xml_to_object_aux ($values);
-       //omit the first tag
-       $parts = array_keys(get_object_vars($res));
-       $key = $parts[0];
-       return $res->$key;
+    $xml=utf8_encode($xml);
+
+    //create the parser
+    $parser = xml_parser_create ();
+    xml_set_default_handler ($parser,'basicxml_xml_to_object_aux');
+
+    $values = array();
+    $index = array();
+    xml_parse_into_struct($parser,$xml,$values,$index);
+
+    //print_object($values);
+    //print_object($index);
+
+    //just simplexml tag (disabled)
+    //if (strtolower($values[0]['tag']) != 'basicxml') return false;
+    //if (strtolower($values[count($values)-1]['tag']) != 'basicxml') return false;
+
+    $res = basicxml_xml_to_object_aux ($values);
+    //omit the first tag
+    $parts = array_keys(get_object_vars($res));
+    $key = $parts[0];
+    return $res->$key;
 }
 
 /**
  * auxiliar function to basicxml_xml_to_object
- * 
+ *
  * @author ferran recio
- * 
+ *
  * @param mixed $values
- * 
+ *
  * @return mixed
  */
 function basicxml_xml_to_object_aux ($values) {
-       
-       if (!is_array($values)) return false;
-       //print_object ($values);
-       $currset = array();
-       $search = false;
-       
-       foreach ($values as $value) {
-               $tag = strtolower($value['tag']);
-               //if we are acomulating, just acomulate it
-               if ($search) {
-                       //if it closes a tag, we just stop searching
-                       if ($tag == $search && $value['type']=='close') {
-                               //recursivity
-                               $obj2 = basicxml_xml_to_object_aux ($currset);
-                               //search cleaning
-                               $search = false;
-                               //add to result
-                               if (isset($res->{$tag})){
-                                       if (is_array($res->{$tag})){
-                                                       $res->{$tag}[] = $obj2;
-                                       } else {
-                                               $res->{$tag} = array($res->{$tag},$obj2);
-                                       }
-                               } else {
-                                       $res->{$tag} = $obj2;
-                               }
-                       } else {
-                               //we are searching. If it's cdada, pass it throw
-                               if ($value['type']=='cdata') continue;
-                               //if isn't cdata, put it in the set and continue searching
-                               //(because isn't the close we're searching)
-                               $currset[] = $value;
-                       }
-               } else {
-                       //walking the xml
-                       if ($value['type']=='open'){
-                               //on open, let's search on it
-                               $currset = array();
-                               $search = $tag;
-                       } else {
-                               //if it's complete just save it
-                               if ($value['type']=='complete') {
-                                       $val = html_entity_decode($value['value']);
-                                       if (isset($res->{$tag})){
-                                               if (is_array($res->{$tag})){
-                                                               $res->{$tag}[] = $val;
-                                               } else {
-                                                       $res->{$tag} = array($res->{$tag},$val);
-                                               }
-                                       } else {
-                                               $res->{$tag} = $val;
-                                       }
-                               }
-                       }
-               }
-       }
-       return $res;
+
+    if (!is_array($values)) return false;
+    //print_object ($values);
+    $currset = array();
+    $search = false;
+
+    foreach ($values as $value) {
+        $tag = strtolower($value['tag']);
+        //if we are acomulating, just acomulate it
+        if ($search) {
+            //if it closes a tag, we just stop searching
+            if ($tag == $search && $value['type']=='close') {
+                //recursivity
+                $obj2 = basicxml_xml_to_object_aux ($currset);
+                //search cleaning
+                $search = false;
+                //add to result
+                if (isset($res->{$tag})){
+                    if (is_array($res->{$tag})){
+                        $res->{$tag}[] = $obj2;
+                    } else {
+                        $res->{$tag} = array($res->{$tag},$obj2);
+                    }
+                } else {
+                    $res->{$tag} = $obj2;
+                }
+            } else {
+                //we are searching. If it's cdada, pass it throw
+                if ($value['type']=='cdata') continue;
+                //if isn't cdata, put it in the set and continue searching
+                //(because isn't the close we're searching)
+                $currset[] = $value;
+            }
+        } else {
+            //walking the xml
+            if ($value['type']=='open'){
+                //on open, let's search on it
+                $currset = array();
+                $search = $tag;
+            } else {
+                //if it's complete just save it
+                if ($value['type']=='complete') {
+                    if (!empty($value['value']  )) {
+                        $val = html_entity_decode($value['value']);
+                        if (isset($res->{$tag})){
+                            if (is_array($res->{$tag})){
+                                $res->{$tag}[] = $val;
+                            } else {
+                                $res->{$tag} = array($res->{$tag},$val);
+                            }
+                        } else {
+                            $res->{$tag} = $val;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return $res;
 }
 ?>
\ No newline at end of file