    public static function convertToXML($json, $standalone = true)
    {
        self::$dom = new DomDocument('1.0', 'utf-8');
        self::$dom->formatOutput = true;

        // remove callback functions from JSONP
        if (preg_match('/(\{|\[).*(\}|\])/s', $json, $matches)) {
            $json = $matches[0];
        } else {
            throw new JSONException(__("JSON not formatted correctly"));
        }

        $data = json_decode($json);
        if (function_exists('json_last_error')) {
            if (json_last_error() !== JSON_ERROR_NONE) {
                throw new JSONException(__("JSON not formatted correctly"), json_last_error());
            }
        } elseif (!$data) {
            throw new JSONException(__("JSON not formatted correctly"));
        }

        $data_element = self::_process($data, self::$dom->createElement('data'));
        self::$dom->appendChild($data_element);

        if ($standalone) {
            return self::$dom->saveXML();
        } else {
            return self::$dom->saveXML(self::$dom->documentElement);
        }
    }