Php XML解析错误-文档末尾有额外内容

Php XML解析错误-文档末尾有额外内容,php,xml,Php,Xml,我试图给出获取JSON或XML响应的选项 JSON工作得很好,但是当我查看XML时,会出现一个错误 我不确定出了什么问题。我已经搜索过了,我看到的唯一一件事就是确保我的元素名中没有多余的空格,甚至没有空格,而我没有 index.php <?php require_once('includes/inc.settings.php'); if(${'Response'}['format'] == 'json'){ print_r(${'Results'}); }elseif(${

我试图给出获取JSON或XML响应的选项

JSON工作得很好,但是当我查看XML时,会出现一个错误

我不确定出了什么问题。我已经搜索过了,我看到的唯一一件事就是确保我的元素名中没有多余的空格,甚至没有空格,而我没有

index.php

<?php
require_once('includes/inc.settings.php');
if(${'Response'}['format'] == 'json'){
    print_r(${'Results'});  
}elseif(${'Response'}['format'] == 'xml'){
    header('Content-type: application/xml');
    echo "<?xml version=\"1.0\"?>";
    echo ${'Results'};
}
?>

inc.settings.php

<?php
// ****************************************
// Require other includes 
// ****************************************
    require('Excel/PHPExcel.php');
    require('inc.variables.php');
    require('inc.functions.php');
    require('inc.browser.php');
    require('class.phpmailer.php');

// ****************************************
// Initial page setup
// ****************************************

    // Set our Error Handling
    if($debug == true){
        error_reporting(E_ALL);
        ini_set('display_errors', 1);
    } else {
        error_reporting(E_ERROR);
        ini_set('display_errors', 1);
    }

    // Set our timeout limit
    set_time_limit(30);

    // Set our memory limit
    ini_set('memory_limit', '128M');

    // Start our PHP session
    session_start();

    // Set our charset to UTF-8
    mb_internal_encoding('UTF-8');

    // Get our browser information
    $browser = new Browser;

// ****************************************
// Connect to mySQL
// ****************************************
    mysql_connect(MYSQL_HOST.':'.MYSQL_PORT, MYSQL_USER, MYSQL_PASS) or die('Could not establish a connection to the MySQL Engine.');
    mysql_select_db(MYSQL_DB) or die('Could not locate the specified database');


// ****************************************
// Sanitize our possible api data
// ****************************************

    if(isset($_GET['api_key'])) { ${'API KEY'} = inputCleanSQL($_GET['api_key']); } else { ${'API KEY'} = ''; } 
    if(isset($_GET['format'])){ ${'Format'} = inputCleanSQL($_GET['format']); } else { ${'Format'} = ''; }
    if(isset($_GET['act'])){ ${'Action'} = inputCleanSQL($_GET['act']); } else { ${'Action'} = ''; }
    if(isset($_GET['phone_numer'])){ ${'Phone Number'} = inputCleanSQL(removeCHARSphone($_GET['phone_number'])); } else { ${'Phone Number'} = ''; }
    if(isset($_GET['limit'])){ ${'Limit'} = inputCleanSQL($_GET['limit']); } else { ${'Limit'} = ''; }

// ****************************************
// Begin the Response Array
// ****************************************

    ${'Response'} = array();
    ${'Response'}['status'] = '';
    ${'Response'}['reason'] = array();
    ${'Format Type'} = true;

// Check the API Key
if(isset(${'API KEY'})){
    ${'API Key Check'} = mysql_result(mysql_query('SELECT count(0) FROM `api`.`api_keys` WHERE `api_key` = "'.${'API KEY'}.'"'),0);
    if(!${'API Key Check'}) {
        ${'Response'}['status'] = 'failed';
        ${'Response'}['reason'][] = 'invalid api key';
    } else {
        // Log the API hit
        mysql_query('INSERT INTO `api`.`api_log` (`api_key`) VALUES ("'.${'API KEY'}.'")');

        // Check the format request
        if(${'Format'} != '' && ${'Format'} != 'json' && ${'Format'} != 'xml'){
            ${'Response'}['status'] = 'failed';
            ${'Response'}['reason'][] = 'invalid format specified (&format=)';
            ${'Format Type'} = false;
        }

        // Check the action request
        if(${'Action'} != '' && ${'Action'} != 'get' && ${'Action'} != 'details'){
            ${'Response'}['status'] = 'failed';
            ${'Response'}['reason'][] = 'invalid action type (&act=)';
        }

        if(${'Response'}['status'] != 'failed'){
            ${'Response'}['status'] = 'success';
            unset(${'Response'}['reason']);
        }

    }
} else {
    ${'Response'}['status'] = 'failed';
    ${'Response'}['reason'][] = 'api key required';
}


if(isset(${'Format'}) && ${'Format Type'}){
    if(${'Format'} == 'json'){
        ${'Response'}['format'] = 'json';
        ${'Results'} = json_encode(${'Response'});
    } elseif(${'Format'} == 'xml'){
        ${'Response'}['format'] = 'xml';
        ${'Results'} = arrayToXML(${'Response'});
    }
} else {
    ${'Response'}['format'] = 'json';
    ${'Results'} = json_encode(${'Response'});
}
?>

任何帮助都将不胜感激

XML只能有一个“文档实体”或“根”,您试图使用两个(
status
format
)。将两个元素包装在一个元素中,以便XML文档只有一个根元素

坏的

<?xml version="1.0"?>
<status>success</status>
<format>xml</format>
<?xml version="1.0"?>
<response>
  <status>success</status>
  <format>xml</format>
</response>

成功
xml

<?xml version="1.0"?>
<status>success</status>
<format>xml</format>
<?xml version="1.0"?>
<response>
  <status>success</status>
  <format>xml</format>
</response>

成功
xml

确保您还三次检查文档顶部是否有重复的urlset声明。这是我的问题。这是一个非常粗心的疏忽

    <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9" 
url="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" 
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

我在这里提出了另一个问题,可能是重复的