Código PHP:
<?php
include ("../../config.php");
mysql_connect("$dbhost","$dbuser","$dbpass");
mysql_select_db("$db");
$query = "SELECT id, titulo, descripcion, resumen, banner, activar FROM packs;";
$result = mysql_query($query);
$xml = new DomDocument('1.0', 'UTF-8');
//NODO PRINCIPAL
$root = $xml->createElement('noticias');
$root = $xml->appendChild($root);
//NODOS HIJOS
while($array = mysql_fetch_array($result)) {
$noticia=$xml->createElement('noticia');
$noticia =$root->appendChild($noticia);
$child = $xml->createElement('id');
$child = $noticia->appendChild($child);
$value = $xml->createTextNode($array['id']);
$value = $child->appendChild($value);
$child = $xml->createElement('titulo');
$child = $noticia->appendChild($child);
$value = $xml->createTextNode($array['titulo']);
$value = $child->appendChild($value);
$child = $xml->createElement('resumen');
$child = $noticia->appendChild($child);
$value = $xml->createTextNode($array['resumen']);
$value = $child->appendChild($value);
$child = $xml->createElement('accion');
$child = $noticia->appendChild($child);
$value = $xml->createTextNode($array['activar']);
$value = $child->appendChild($value);
$child = $xml->createElement('contenido');
$child = $noticia->appendChild($child);
$value = $xml->createTextNode(utf8_encode($array['descripcion']));
$value = $child->appendChild($value);
$child = $xml->createElement('banner');
$child = $noticia->appendChild($child);
$value = $xml->createTextNode($array['banner']);
$value = $child->appendChild($value);
}
$xml->formatOutput = true;
$strings_xml = $xml->saveXML();
//$xml->save('XML/prueba.xml');
//$xml_string = $xml->saveXML();
echo $strings_xml;
?>