title: Symfony 2: Prevent header display in xml response
body: <p>So I'm trying to create a xml document with symfony. The generation works without issues and I return the document with a twig templates named <code>sitemap.xml.twig</code> in the following way:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt;
      {% for slug in slugArray %}
      &lt;url&gt;
          &lt;loc&gt;{{ slug }}&lt;/loc&gt;
          &lt;lastmod&gt;{{ curDate }}&lt;/lastmod&gt;
          &lt;changefreq&gt;monthly&lt;/changefreq&gt;
          &lt;priority&gt;0.5&lt;/priority&gt;
      &lt;/url&gt;
      {% endfor %}
  &lt;/urlset&gt;
  </code></pre>
  
  <p>In the controller, I call the template with:</p>
  
  <pre><code>    $response = new Response($this-&gt;render(
          'MyBundle:Sitemap:sitemap.xml.twig',
          [
              'slugArray' =&gt; $slugArray,
              'curDate' =&gt; $curDate
          ]
      ));
  
      $response-&gt;headers-&gt;set('Content-Type', 'application/xml; charset=utf-8');
  
      return $response;
  </code></pre>
  
  <p><code>$slugArray</code> contains around 1000 links which are all valid, while <code>$curDate</code> contains the value of <code>date('Y-m-d', time())</code>. </p>
  
  <p>However, when I try to to access the sitemap, I get the following error:</p>
  
  <pre><code>XML-Verarbeitungsfehler: nicht wohlgeformt
  Adresse: http://localhost:8888/myWebsite/sitemap.xml
  Zeile Nr. 1, Spalte 5:
  
  HTTP/1.0 200 OK
  ----^
  </code></pre>
  
  <p>This is basically meaning the xml document is not well formed.</p>
  
  <p>So for some reason, the header is taken into account when parsing the xml, creating an error. The xml itself is completely valid, when I copy the response from the dev tools in firefox, leave the header and check them with online validators, I get no error. </p>
  
  <p>When I remove the <code>$response-&gt;headers-&gt;set('Content-Type', 'application/xml; charset=utf-8');</code>, I get plain HTML.</p>
  
  <p>So how can I create an xml response which can be parsed by a browser without issues?</p>