diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-08-01 19:48:51 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-08-01 19:48:51 +0200 |
commit | 93daa9e247e9c423a6d4bb10af1106fdde37b800 (patch) | |
tree | 1ff12f380c613cd8b4b04a5086763098d9571d67 /lib/api.php | |
parent | c11c2d0fd46fbe2e74ff7fe2ff7205c5cb38ea9f (diff) | |
download | nextcloud-server-93daa9e247e9c423a6d4bb10af1106fdde37b800.tar.gz nextcloud-server-93daa9e247e9c423a6d4bb10af1106fdde37b800.zip |
API: Complete respond function
Diffstat (limited to 'lib/api.php')
-rw-r--r-- | lib/api.php | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/api.php b/lib/api.php index 454a6fd26d3..6ee570d60e7 100644 --- a/lib/api.php +++ b/lib/api.php @@ -115,13 +115,32 @@ class OC_API { */ private static function respond($response, $format='json'){ if ($format == 'json') { - echo json_encode($response); - //} else if ($format == 'xml') { - // TODO array to xml + OC_JSON::encodedPrint($response); + } else if ($format == 'xml') { + header('Content-type: text/xml; charset=UTF-8'); + $writer = new XMLWriter(); + $writer->openMemory(); + $writer->setIndent( true ); + $writer->startDocument(); + self::toXML($response, $writer); + $writer->endDocument(); + echo $writer->outputMemory(true); } else { var_dump($format, $response); } } + + private static function toXML($array, $writer){ + foreach($array as $k => $v) { + if (is_array($v)) { + $writer->startElement($k); + self::toXML($v, $writer); + $writer->endElement(); + } else { + $writer->writeElement($k, $v); + } + } + } /** * check if the user is authenticated |