title: Alternative to header("Content-type: text/xml");
body: <p>Is there an equivalent to the following:</p>
  
  <pre><code>header("Content-type: text/xml");
  </code></pre>
  
  <p>I'm using Google Maps with Wordpress and I get the "headers already sent" error. I've gone through all the files and taken out all the whitespace but the error still appears so just wondering if there was another way of doing the code above.</p>
  
  <p>This is the error:</p>
  
  <pre><code>Warning: Cannot modify header information - headers already sent by (output started at /home/medicom/public_html/mapping/wp-content/themes/default/header.php:11) in /home/medicom/public_html/mapping/wp-content/themes/default/new-version1.php on line 45
  </code></pre>
  
  <p>And this is my page - <a href="http://www.mediwales.com/mapping/test/" rel="noreferrer">http://www.mediwales.com/mapping/test/</a></p>
  
  <pre><code>&lt;?php
  /**
   * @package WordPress
   * @subpackage Default_Theme
   * Template Name: Latest Version
   */
  ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head profile="http://gmpg.org/xfn/11"&gt;
  &lt;meta http-equiv="Content-Type" content="&lt;?php bloginfo('html_type');?&gt;; charset=&lt;?php bloginfo('charset');?&gt;" /&gt;
  &lt;title&gt;&lt;?php wp_title('&amp;laquo;', true, 'right');?&gt;&lt;/title&gt;
  &lt;link rel="stylesheet" href="&lt;?php bloginfo('stylesheet_url');?&gt;" type="text/css" media="screen" /&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="&lt;?php bloginfo('template_directory'); ?&gt;/markerclusterer.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;link rel="pingback" href="&lt;?php bloginfo('pingback_url'); ?&gt;" /&gt;
  &lt;script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAdnbfsmnsdaFBmEZfsJEmiWC7p0LLmMBSsffI9l26I_viUYjW7vRG7TlO-sRQKR0B_YAsP2VnDdVgsr4Aegvksdw" type="text/javascript"&gt;&lt;/script&gt;
  &lt;?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?&gt;
  &lt;?php wp_head(); ?&gt;
  &lt;/head&gt;
  &lt;body &lt;?php body_class(); ?&gt; onload="load()" onunload="GUnload()"&gt;
      &lt;?php if (have_posts()) : ?&gt;
          &lt;?php while (have_posts()) : the_post(); ?&gt;
      &lt;div id="body"&gt;
  &lt;?php
  require("database.php");
  function parseToXML($htmlStr)
  {
  $xmlStr=str_replace('&lt;','&amp;lt;',$htmlStr);
  $xmlStr=str_replace('&gt;','&amp;gt;',$xmlStr);
  $xmlStr=str_replace('"','&amp;quot;',$xmlStr);
  $xmlStr=str_replace("'",'&amp;#39;',$xmlStr);
  $xmlStr=str_replace("&amp;",'&amp;amp;',$xmlStr);
  return $xmlStr;
  }
  // Opens a connection to a MySQL server
  $connection=mysql_connect (localhost, $username, $password);
  if (!$connection) {
    die('Not connected : ' . mysql_error());
  }
  // Set the active MySQL database
  $db_selected = mysql_select_db($database, $connection);
  if (!$db_selected) {
    die ('Can\'t use db : ' . mysql_error());
  }
  // Select all the rows in the markers table
  $query = "SELECT * FROM markers WHERE 1";
  $result = mysql_query($query);
  if (!$result) {
    die('Invalid query: ' . mysql_error());
  }
  header("Content-type: text/xml");
  // Start XML file, echo parent node
  echo '&lt;markers&gt;';
  // Iterate through the rows, printing XML nodes for each
  while ($row = @mysql_fetch_assoc($result)){
    // ADD TO XML DOCUMENT NODE
    echo '&lt;marker ';
    echo 'name="' . parseToXML($row['name']) . '" ';
    echo 'address="' . parseToXML($row['address']) . '" ';
    echo 'lat="' . $row['lat'] . '" ';
    echo 'lng="' . $row['lng'] . '" ';
    echo 'type="' . $row['type'] . '" ';
    echo '/&gt;';
  }
  // End XML file
  echo '&lt;/markers&gt;';
  ?&gt;
  &lt;script type="text/javascript"&gt;
      //&lt;![CDATA[
      var iconBlue = new GIcon();
      iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
      iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
      iconBlue.iconSize = new GSize(12, 20);
      iconBlue.shadowSize = new GSize(22, 20);
      iconBlue.iconAnchor = new GPoint(6, 20);
      iconBlue.infoWindowAnchor = new GPoint(5, 1);
      var iconRed = new GIcon();
      iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
      iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
      iconRed.iconSize = new GSize(12, 20);
      iconRed.shadowSize = new GSize(22, 20);
      iconRed.iconAnchor = new GPoint(6, 20);
      iconRed.infoWindowAnchor = new GPoint(5, 1);
      var customIcons = [];
      customIcons["restaurant"] = iconBlue;
      customIcons["bar"] = iconRed;
      function load() {
        if (GBrowserIsCompatible()) {
          var map = new GMap2(document.getElementById("map"));
          map.addControl(new GSmallMapControl());
          map.addControl(new GMapTypeControl());
          map.setCenter(new GLatLng(47.614495, -122.341861), 13);
          GDownloadUrl("phpsqlajax_genxml.php", function(data) {
            var xml = GXml.parse(data);
            var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i &lt; markers.length; i++) {
              var name = markers[i].getAttribute("name");
              var address = markers[i].getAttribute("address");
              var type = markers[i].getAttribute("type");
              var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                      parseFloat(markers[i].getAttribute("lng")));
              var marker = createMarker(point, name, address, type);
              map.addOverlay(marker);
            }
          });
        }
      }
      function createMarker(point, name, address, type) {
        var marker = new GMarker(point, customIcons[type]);
        var html = "&lt;b&gt;" + name + "&lt;/b&gt; &lt;br/&gt;" + address;
        GEvent.addListener(marker, 'click', function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }
      //]]&gt;
    &lt;/script&gt;  
    &lt;div id="map" style="width: 500px; height: 300px"&gt;&lt;/div&gt;
  &lt;/div&gt;
          &lt;?php endwhile; ?&gt;
      &lt;?php endif; ?&gt;
  &lt;/div&gt;
  &lt;?php wp_footer(); ?&gt;
  &lt;/body&gt;&lt;/html&gt; 
  </code></pre>