How do I add `header("Content-type: text/xml");`

Do I need to add header("Content-type: text/xml");to my script or somewhere in my site in order to create XML? If so, how do I go about doing that?

code snippet that requires the header:

header("Content-type: text/xml");

$dom = new DOMDocument("1.0");
$node = $dom->createElement($wpdb->prefix.'address_table');
$parnode = $dom->appendChild($node); 

 $node = $dom->createElement("marker");
          $newnode = $parnode->appendChild($node);
          $newnode->setAttribute("lat",$data->results[0]->geometry->location->lat);
          $newnode->setAttribute("lng", $data->results[0]->geometry->location->lng); 

echo $dom->saveXML();

This is the error when I load the xml script: error on line 7 at column 45: Entity 'raquo' not defined

I have this working in a non-Wordpress site, so, I'm pretty sure I'm running into the same issue ( which I did get working in the non-Wordpress version )
see here: http://stackoverflow.com/questions/19601885/evaluating-xml-document-element-gives-type-issue-null-is-not-an-object

This is the console log error I get now for the wordpress site : Uncaught TypeError: Cannot read property 'documentElement' of null

That is the same error recieved for the non-Wordpress site. So, It seems that I need to have header("Content-type: text/xml"); added, but it needs to be added before wordpress outputs anything else.

I tried adding header("Content-type: text/xml"); to header.php file, but that doens't work, and beside that would add it to every page, which of course is not what I need anyway.

Finally, The data is getting pulled from the database, and even displayed in the console. (same as other site did). Again, it is the same as non-Wordpress, however this being wordpress, it's different when and where things need to be placed.
Thanks ~