ccc

Crear XML desde php

 $content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><root>';
        foreach($productos as $producto) {
            $content .= "<producto>";
            $content .= "<nombre>".$producto->nombre."</nombre>";
            $content .= "<descripcion>".$producto->descripcion."</descripcion>";
            $content .= "<imagen>.$producto->imagen.</imagen>";
            $content .= "</producto>";
        }
        $content .= "</root>";

header( 'Content-Description: File Transfer');
header( 'Content-Type: application/xml' );
header( 'Content-Disposition: attachment; filename=productos.xml' ); 
header( 'Content-Transfer-Encoding: binary');
header( 'Connection: Keep-Alive');
header( 'Expires: 0');
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0');
header( 'Pragma: public' );
header( 'Content-Length: '.strlen( $content ) );
echo $content; // genera el XML

No hay comentarios:

Publicar un comentario