Beruflich Dokumente
Kultur Dokumente
Laboratorio de Introduccin
Pag. - 1 -
Pag. - 2 -
font-size: 14pt;
text-indent: 12px;
}
relacion {
display: block;
color: yellow;
font-family: Courier, monospace;
font-size: 14pt;
text-indent: 12px;
}
email {
display: block;
color: blue;
font-family: Courier, monospace;
Pag. - 3 -
Pag. - 4 -
writer {
display: block;
color: blue;
font-family: Courier, monospace;
font-size: 14pt;
text-indent: 12px;
}
producer {
display: block;
color: red;
font-family: Western, fantasy;
font-size: 12pt;
text-indent: 12px;
}
director {
display: block;
color: green;
font-family: Times, serif;
font-size: 14pt;
text-indent: 12px;
}
actor {
display: block;
color: fuchsia;
font-family: Zapf-Chancery, cursive;
font-size: 20pt;
text-indent: 12px;
}
comments {
display: none;
}
Pag. - 5 -
<MENSAJE prioridad="maxima">
<CABECERA>
<FECHA fd="09" fm="01" fa="2008" />
<DE>Toms Nogales</DE>
<A>Menchu Arellano</A>
<ASUNTO>Reunin proyecto</ASUNTO>
</CABECERA>
<CUERPO>
<SALUDO>Hola de nuevo.</SALUDO>
<P>En relacin con tu mensaje:</P>
<CITA>tendra que ser una tarde de esta
semana.</CITA>
<P>Yo slo podra el <ENFASIS>jueves o el
viernes</ENFASIS>.</P>
<DESPEDIDA>Saludos.</DESPEDIDA>
<FIRMANTE>Toms</FIRMANTE>
</CUERPO>
</MENSAJE>
Pag. - 6 -
fclose($fp);
print ('Creado Feed RSS.');
?>
<?php
$fp = fopen('index.xml', 'w');
$rand = "\n";
fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>' .$rand);
fwrite($fp, '<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom">' .$rand);
fwrite($fp, '<channel>' .$rand);
fwrite($fp, '<title>UIGV' .$dirname. '</title>' .$rand);
fwrite($fp, '<description>Bj - El blog de un linuxero</description>' .
$rand);
fwrite($fp, '<link>http://www.somoslibres.org' .$dirname. '/</link>' .
$rand);
fwrite($fp, '<language>es-sp</language>' .$rand);
fwrite($fp, '<copyright>Copyright ' .date('Y'). '
SomosLibres.org</copyright>' .$rand .$rand);
$db=mysql_connect('localhost','root','uigv');
mysql_select_db('noticias',$db);
$sql = "SELECT * FROM articulos ORDER BY fecha
DESC";
$result = mysql_query($sql) or die('No se ha podido realizar la
consulta.');
while ($row = mysql_fetch_array($result)) {
$id
= $row['id'];
$categoria = strip_tags($row['categoria']);
$titulo = htmlentities(strip_tags($row['titulo']), ENT_QUOTES);
$resumen = htmlentities(strip_tags($row['resumen']),
ENT_QUOTES);
$fecha = $row['fecha'];
$enlace = $row['enlace'];
fwrite($fp, '<item>' .$rand);
fwrite($fp, '<title>' .$titulo. '</title>' .$rand);
fwrite($fp, '<description>' .$resumen. '</description>' .$rand);
fwrite($fp, '<category>![CDATA[' .$categoria. ']]</category>' .
$rand);
fwrite($fp, '<link>' .$enlace. '</link>' .$rand);
fwrite($fp, '<pubDate>' .date('D, d M Y H:i:s O', strtotime($fecha)).
'</pubDate>' .$rand);
fwrite($fp, '</item>' .$rand .$rand);}
Figura 23: Las noticias estn listas para ser distribuidas desde
Firefox
Pag. - 7 -
Pag. - 8 -
/* Recorremos el XML */
$count=0;
foreach ($xml->libro as $libro) {
// Inserta el libro en la tabla
$qry = "INSERT INTO libros ".
"(codigo, titulo, editorial, autor, descripcion,precio)".
" VALUES ('$libro->ref', ".
"'$libro->titulo', ".
"'$libro->editorial', ".
"'$libro->autor', ".
"'$libro->desc', ".
$libro->precio.")";
// Ahora ejecutamos el INSERT en la BD
$result = mysql_query($qry) or die(mysql_error());
// Y necesitamos recuperar el ultimo ID para relacionar sus
imagenes
$libro_id = mysql_insert_id ();
// Y ahora sus imgenes (en este caso tiene 3)
for ($i=0;$i<3;$i++) {
$img_url = $libro->images->image[$i]->url;
$img_des = $libro->images->image[$i]->titulo;
$qry = "INSERT INTO img_libros (libro_id, url, descripcion) ".
"VALUES ($libro_id, '$img_url', '$img_des')";
$result = mysql_query($qry) or die(mysql_error());
}
// Incrementamos contado para ver cuntos libros se importan.
$count++;
}
VIII. ACTIVIDADES
8.1 Plantear un enunciado para el caso persona
y caso movies.
8.2 Proponer el codigo en XSD para la aplicacin
Movies y Mensaje
8.3 Generar un archivo XML a partir de un
programa en PHP de un sistema de Biblioteca.
8.4 Exportar de MYSQL a XML el ltimo caso del
problema
8.5 Llevar 2 libros con sus respectivas imgenes
a MYSQL, utilizando el archivo libros.xml
Universidad Inca Garcilaso de la Vega
FACULTAD DE INGENIERA DE SISTEMAS, CMPUTO y
TELECOMUNICACIONES
Docente: MSc. Daniel Alejandro Yucra Sotomayor
Lima, Abril, del 2012
Consultas: danielyucra@gmail.com
echo "<br/>";
echo "-------------------------------------------<br/>";
echo "Total de libros importados: $count en total<br/>";
echo "-------------------------------------------<br/>";
?>
Pag. - 9 -