title: XML Parse Error - Extra content at the end of the document
body: <p>I am trying to give the option to get either a JSON or XML response.</p>
  
  <p>JSON works fine but when I view the XML, I get an error.</p>
  
  <p><a href="http://lmsapi.com/?api_key=fba9e59d7af86b239e82581780ff987e&amp;format=json">http://lmsapi.com/?api_key=fba9e59d7af86b239e82581780ff987e&amp;format=json</a>
  <a href="http://lmsapi.com/?api_key=fba9e59d7af86b239e82581780ff987e&amp;format=xml">http://lmsapi.com/?api_key=fba9e59d7af86b239e82581780ff987e&amp;format=xml</a></p>
  
  <p>I'm not sure what is going wrong. I have searched and the only thing I see is to make sure that I don't have any extra whitespace or even have spaces in my element names, which I don't.</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
  require_once('includes/inc.settings.php');
  if(${'Response'}['format'] == 'json'){
      print_r(${'Results'});  
  }elseif(${'Response'}['format'] == 'xml'){
      header('Content-type: application/xml');
      echo "&lt;?xml version=\"1.0\"?&gt;";
      echo ${'Results'};
  }
  ?&gt;
  </code></pre>
  
  <p>inc.settings.php</p>
  
  <pre><code>&lt;?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'} != '' &amp;&amp; ${'Format'} != 'json' &amp;&amp; ${'Format'} != 'xml'){
              ${'Response'}['status'] = 'failed';
              ${'Response'}['reason'][] = 'invalid format specified (&amp;format=)';
              ${'Format Type'} = false;
          }
  
          // Check the action request
          if(${'Action'} != '' &amp;&amp; ${'Action'} != 'get' &amp;&amp; ${'Action'} != 'details'){
              ${'Response'}['status'] = 'failed';
              ${'Response'}['reason'][] = 'invalid action type (&amp;act=)';
          }
  
          if(${'Response'}['status'] != 'failed'){
              ${'Response'}['status'] = 'success';
              unset(${'Response'}['reason']);
          }
  
      }
  } else {
      ${'Response'}['status'] = 'failed';
      ${'Response'}['reason'][] = 'api key required';
  }
  
  
  if(isset(${'Format'}) &amp;&amp; ${'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'});
  }
  ?&gt;
  </code></pre>
  
  <p>Any help would be much appreciated!</p>