Exemplo n.º 1
0
 public static function recurseXml($data, $rootNodeName = 'data', $xml = null)
 {
     if ($xml === null) {
         $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />");
     }
     // loop through the data passed in.
     foreach ($data as $key => $value) {
         if (is_object($data) && method_exists($data, "get_" . $key)) {
             //$value = call_user_method("get",$data,$key);
             $value = $data->get($key);
         }
         // no numeric keys in our xml please!
         if (is_numeric($key)) {
             // make string key...
             //$key = "unknownNode_". (string) $key;
             $key = "array";
         }
         // replace anything not alpha numeric
         $key = preg_replace('/[^a-z_0-9]/i', '', $key);
         // if there is another array found recrusively call this function
         if (strpos($key, '_') === 0) {
         } else {
             if (is_array($value) || is_object($value)) {
                 $node = $xml->addChild($key);
                 // recrusive call.
                 WebVista_Model_ORM::recurseXml($value, $rootNodeName, $node);
             } else {
                 // add single node.
                 if (is_resource($value)) {
                     $value = "resource";
                 }
                 $value = htmlentities(iconv("UTF-8", "ASCII//TRANSLIT", $value));
                 $xml->addChild($key, $value);
             }
         }
     }
     // pass back as string. or simple xml object if you want!
     $xmlstr = $xml->asXML();
     return preg_replace('/<\\?.*\\?>/', '', $xmlstr);
 }
Exemplo n.º 2
0
 function toXml()
 {
     return WebVista_Model_ORM::recurseXml($this->_data, $this->systemName);
 }