I'm trying to make a web service in PHP for an app to communicate with that will get data from a database and put it into XML format for the app. One of the columns, however, contains HTML and needs to be outputted (I think) as CDATA. I'm having trouble accomplishing this though. Please advise
<?php
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME);
$sql = "SELECT post_date_gmt, post_content, post_title FROM [schema].wp_posts WHERE post_status = \"publish\" && post_type = \"post\" ORDER BY post_date_gmt DESC;";
$res = mysql_query($sql);
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('BlogPosts');
while ($row = mysql_fetch_assoc($res)) {
$xml->startElement("Post");
$xml->startElement("PostDate");
$xml->writeRaw($row['post_date_gmt']);
$xml->endElement();
$xml->startElement("PostTitle");
$xml->$writeRaw($row['post_title']);
$xml->endElement();
$xml->startCData("PostContent");
$xml->writeCData($row['post_content']);
$xml->endCData();
$xml->endElement();
}
$xml->endElement();
header('Content-type: text/xml');
$xml->flush();
?>
Thank you very much in advance for any assistance you could offer!