Not sure if this is the right forum.

I am using this code to take data from the sql database and convert it into an xml file. However some of the row results from the mysql database have characters that cause errors with the xml file and it doesn't close the elements. For example if there is an apostrophe or euro sign. I thought the using writecdata would sort it but it still failed (also is the resulting xml meant to show the element as <![CDATA[ name ]]> ?)

include ("db.php");
global $dbServer, $dbUser, $dbPass, $dbName;
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$sql_0 = "SELECT Name FROM properties";
$query0 = mysql_query($sql_0) or die("Cannot query the database.<br>" . mysql_error());

$xml = new XMLWriter();
$xml->startDocument('1.0', 'UTF-8');


while($row = mysql_fetch_array($query0)){
$name = $row["Name"];
  $xml->writeCData ($name);

header('Content-type: application/xml; charset=utf-8');
header('Content-type: text/xml');
Any help or pointers would be appreciated.