2011-03-14 15 views
10

Actualmente estoy usando XMLWriter para mostrar un archivo xml. Sin embargo, me gustaría saber cómo podría exportar la salida a un archivo .xml.Salida XMLWriter a archivo XML

Mi código actual es:

$res = mysql_query($sql); 

$xml = new XMLWriter(); 

$xml->openURI("php://output"); 
$xml->startDocument(); 
$xml->startElement('stores'); 

while ($row = mysql_fetch_assoc($res)) { 
//loads of code 
} 
$xml->endElement(); 

$xml->flush(); 

Respuesta

20

utilizan un nombre en lugar de php://output en el método openURI().

$writer = new XMLWriter(); 
$writer->openURI('test.xml'); 
$writer->startDocument("1.0"); 
$writer->startElement("greeting"); 
$writer->text('Hello World'); 
$writer->endDocument(); 
$writer->flush(); 
+0

¿Sabe si es posible crear el directorio si no existe? –

+3

@Marcio Siempre puedes hacerlo con http://php.net/mkdir – Gordon

Cuestiones relacionadas