createElement('result'); $doc->appendChild($root); $this->xml_recursive($doc, $root, $data); return $doc->saveXML(); } private function xml_recursive(&$doc, &$parent, $data) { if (is_object($data)) { $data = get_object_vars($data); } if (is_array($data)) { $assoc = FALSE || empty($data); foreach ($data as $key => $value) { if (is_numeric($key)) { $key = 'item'; } else { $assoc = TRUE; $key = preg_replace('/[^A-Za-z0-9_]/', '_', $key); $key = preg_replace('/^([0-9]+)/', '_$1', $key); } $element = $doc->createElement($key); $parent->appendChild($element); $this->xml_recursive($doc, $element, $value); } if (!$assoc) { $parent->setAttribute('is_array', 'true'); } } elseif ($data !== NULL) { $parent->appendChild($doc->createTextNode($data)); } } } class ServicesYAMLFormatter implements ServicesFormatterInterface { public function render($data) { if (($library = libraries_load('spyc')) && !empty($library['loaded'])) { return Spyc::YAMLDump($data, 4, 60); } else { watchdog('REST Server', 'Spyc library not found!', array(), WATCHDOG_ERROR); return ''; } } } class ServicesBencodeFormatter implements ServicesFormatterInterface { public function render($data) { module_load_include('php', 'rest_server', 'lib/bencode'); return bencode($data); } }