Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/08/2004, 14:35
angaturama
 
Fecha de Ingreso: abril-2004
Ubicación: México
Mensajes: 10
Antigüedad: 20 años
Puntos: 0
xml y php pregunta

Hola buen dia
Tengo un codigo php que me genera un xml. la unica duda que tengo es que quiero insertar un CDATA para que me respete todo ya en el xml, pero no encuentro la manera de hacerlo.

Este es mi codigo y señale con negritas la parte donde lo quisiera poner, alguien me podría orientar a como hacerlo. o no se puede agregar un cdata a un atributo y tiene que ser a un nodo completo

$connection = mysql_connect("localhost","root", "")
or die ("could not connect to database");

//to select the database here test is the sample database come with mysql
$db = mysql_select_db("test",$connection)
or die ("Couldn't select database.");
$result = mysql_query("select * from flash_news",$connection)
or die ("invalid query");
$num = mysql_num_rows($result);
if ($num != 0) {

$file= fopen("results.xml", "w");
$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";

$_xml .="<mgcontadores>\r\n";

while ($row = mysql_fetch_array($result)) {
if ($row["title"]) {
$_xml .="\t<page id=\"" . $row["id"] . "\" timestamp=\"" . $row["timestamp"] . "\" title=\"" . $row["title"] . "\" body=\"" . $row["body"] ."\">\r\n";
$_xml .="\t</page>\r\n";
} else {
$_xml .="\t<page title=\"Nothing Returned\">\r\n";
$_xml .="\t</page>\r\n";
} }
$_xml .="</mgcontadores>";
fwrite($file, $_xml);
fclose($file);
echo "XML has been written. <a href=\"results.xml\">View the XML.</a>";
} else {
echo "No Records found";
}
?>

saludos
david