[英]using <![CDATA in xml response
I have looked for an answer to this question but I have been unable to find an answer that works for my application. 我一直在寻找这个问题的答案,但是找不到适合我的应用程序的答案。
I need to give a response from a sql query in xml format but the response is a url so i will need to use cdata. 我需要以xml格式给出来自sql查询的响应,但是响应是url,因此我将需要使用cdata。 Here is my code.
这是我的代码。
if ($_POST['action']=="getSermon")
{
//echo"You got it";
$SQL = "SELECT * FROM sermons";
$allsermon = mysql_query($SQL);
$sermonrow = mysql_fetch_assoc($allsermon);
header('Content-type: text/xml; charset=utf-8');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');
$xml = '<?xml version="1.0" encoding="utf-8"?>';
echo $xml;
echo "<SERMON_INFO>";
do {
echo "<SERMON>";
echo "<ID>" . $sermonrow['id'] . "</ID>";
echo "<NAME>" . $sermonrow['Name'] . "</NAME>";
echo "<URL>".<![CDATA[$sermonrow['url']]>."</NAME>";
//echo "<URL>". $sermonrow['url'] . "</URL>";
echo "</SERMON>";
mysql_free_result($result);
} while ($sermonrow = mysql_fetch_assoc($allsermon));
mysql_free_result($allsermon);
echo "</SERMON_INFO>";
mysql_close($db);
}
when i do this i get an error 500 and the page will not load. 当我这样做时,我得到一个错误500,并且该页面无法加载。
The correct syntax is 正确的语法是
echo "<URL><![CDATA[".$sermonrow['url']."]]></URL>";
But I'd rather you use an XML library like DOMDocument or SimpleXML to build your document, more complex, but you'll be less prone to simple errors like mixing up a closing tag name (see </NAME>
). 但是,我希望您使用DOMDocument或SimpleXML之类的XML库来构建您的文档,虽然更为复杂,但是您不太容易出现诸如混合结束标记名(见
</NAME>
)之类的简单错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.