/** * Outputs the dataArray to XML * * @param array $dataArray */ public function toXML($dataArray = array(), $status = 200) { $this->app->contentType("application/xml"); http_response_code($status); $xml = XMLParser::encode($dataArray, "rena"); echo $xml->asXML(); }
return null; } if ($key == 'all') { return json_encode($manager->all()); } return json_encode($manager->get($key)); }); $app->get('/services/{type}/{key}/xml', function ($type, $key) use($app) { $manager = ManagerFactory::getManager($type); if (is_null($manager)) { return null; } if ($type == 'genre') { $data = $manager->getAlbumsByGenre($key); if (!is_null($data)) { $xml = XMLParser::encode($data, 'albums'); Utils::Download(sys_get_temp_dir() . '-' . $key . '.xml', $xml->asXML()); return $app->abort(200); } } return $app->abort(404); }); $app->get('/load/{start_id}:{numbers}', function ($start_id, $numbers) use($app) { $deezer = new DeezerLoader(); $deezer->loadAlbums($start_id, $numbers); return "fin"; }); $app->get('/', function () use($app) { $music_site = new MusicSite(); $data = $music_site->homePage(); return $app['twig']->render($data['page'], $data['params']);
<?php header('Content-type: text/xml'); use XMLParser\XMLParser; $xml = XMLParser::encode(array('attr:status' => 'success', 'Person' => array('attr:id' => 987654321, 'First Name' => 'John', 'Last Name' => 'Smith'), 'Address' => array('attr:' => array('geo-coded' => TRUE, 'lat' => '0.0000', 'lon' => '-0.0000'), 'Street' => '123 Main Street', 'City' => 'Somewhere', 'State' => 'DE', 'Zip' => '12345'), 'other' => array('key' => 'value', array('value1', 'value2', 'value3'))), 'response'); echo $xml->asXML();
<?php header('Content-type: text/xml'); include '../xml-parser.class.php'; use XMLParser\XMLParser; class klass { public $username = '******'; public $password = '******'; public $greeting = 'Johnny boy'; } $data = new klass(); $data->login_attempts = ['2015/01/01 07:21:00', '2015/01/01 07:21:20', '2015/01/01 07:22:15']; $xml = XMLParser::encode($data); echo $xml->asXML();
public function getXmlAsArray() { return XMLParser::decode($this->body); }