/** * Convert an Array to XML * @param string $node_name - name of the root node to be converted * @param array $arr - aray to be converterd * @return DomDocument */ public static function &createXML($node_name, $arr = array()) { $xml = self::getXMLRoot(); $xml->appendChild(self::convert($node_name, $arr)); self::$xml = null; // clear the xml node in the class for 2nd time use. return $xml; }
/** * Output Query in either JSON/XML. The query data is outputted as JSON * by default * * @author Daniel J Griffiths * @since 1.5 * @global $wp_query * * @param int $status_code */ public function output($status_code = 200) { global $wp_query; $format = $this->get_output_format(); status_header($status_code); do_action('spnl_api_output_before', $this->data, $this, $format); switch ($format) { case 'xml': $xml = SendPress_Array2XML::createXML('spnl', $this->data); echo $xml->saveXML(); break; case 'json': header('Content-Type: application/json'); if (!empty($this->pretty_print)) { echo json_encode($this->data, $this->pretty_print); } else { echo json_encode($this->data); } break; default: // Allow other formats to be added via extensions do_action('spnl_api_output_' . $format, $this->data, $this); break; } do_action('spnl_api_output_after', $this->data, $this, $format); spnl_die(); }