class SimpleXMLExtended extends SimpleXMLElement
{
public function addCData($cdata_text)
{
$node = dom_import_simplexml($this);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cdata_text));
}
}
$simple=new SimpleXMLExtended('<message/>');
while($row=mysql_fetch_assoc($res)){
$msg=$simple->addChild('msg');
$msg->addAttribute('id',$row['mid']);
$msg->addAttribute('isread',$row['isread']);
$msg->addChild('pos',$row['pos']);
$msg->addChild('rec',$row['rec']);
$msg->addChild('content');
$msg->content->addCData($row['content']);
}
echo $simple->asXML();
{
public function addCData($cdata_text)
{
$node = dom_import_simplexml($this);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cdata_text));
}
}
$simple=new SimpleXMLExtended('<message/>');
while($row=mysql_fetch_assoc($res)){
$msg=$simple->addChild('msg');
$msg->addAttribute('id',$row['mid']);
$msg->addAttribute('isread',$row['isread']);
$msg->addChild('pos',$row['pos']);
$msg->addChild('rec',$row['rec']);
$msg->addChild('content');
$msg->content->addCData($row['content']);
}
echo $simple->asXML();