php中dom生成的xml怎么输出到页面上

php中dom生成的xml如何输出到页面上
<?php
$id= $_GET['id'];
$n = $_GET['n'];
//包含数据库连接文件
include('conn.php');
$dom=new DomDocument('1.0', 'utf-8');
$dom->formatOutput = true;
if($category == ""){
   exit;
};
//  创建根节点
$element = $dom->createElement('element');
$dom->appendchild($element);
$element->setAttribute('n',$n);
$query = mysql_query( "select * from pictures order by LevelID='$id'" );
while( $result = mysql_fetch_array( $query ) )
{
 $t=$dom->createElement('e');
         $t->setAttribute('cr',$result['c']);
         $t->setAttribute('isNew',$result['isNew']);
         $t->setAttribute('fileUrl',$result['fileUrl']);
         $element->appendChild($t);
         print_r($dom->saveXML());
     
}
echo $dom->saveXML();

?> 
我用print和echo都不能把dom输出到页面上,
请问php里dom生成的xml如何能被输出到页面上,谢谢
dom  xml

------解决方案--------------------
用echo和print都是可以的,但要保证没有其他输出。
否则会因多了其他内容而造成浏览器解析失败
最好还先发一个类型声明:
header("Content-type: text/xml");