Foros del Web » Programando para Internet » PHP »

duda con XML y variables

Estas en el tema de duda con XML y variables en el foro de PHP en Foros del Web. Hola chicos, ya pude leer xml. Lo saqué de una pagina en ingles que ustedes dieron en un post. Mi duda es la siguiente, modifique ...
  #1 (permalink)  
Antiguo 10/08/2005, 23:14
 
Fecha de Ingreso: mayo-2005
Mensajes: 257
Antigüedad: 18 años, 11 meses
Puntos: 1
duda con XML y variables

Hola chicos, ya pude leer xml. Lo saqué de una pagina en ingles que ustedes dieron en un post. Mi duda es la siguiente, modifique el codigo para que lea noticias de un diario, es el siguiente;

<?php
// The name of the XML file to parse
$file_name = 'http://www.lanacion.com.ar/herramientas/rss/index.asp?origen=2';
// Opening element handler function
function startElement($parser, $name, $attrs) {
// What XML element are we working with?
switch ($name) {
case 'CHANNEL':
// Books (root) element - output a new table, caption and table headers

break;
case 'TITLE':
// Book element - output a new row
echo '<p>', "\n";
break;
case 'URL':
// Title element - output a new cell and bold tag

break;

case 'LINK':
// Author or publisher element - output a new cell
echo '<p><font color="#0000FF">', "\n",;
break;

}
}
// Closing element handler function
function endElement($parser, $name) {
// What XML element are we working with?
switch ($name) {
case 'CHANNEL':
// Books (root) element - output closing table tag

break;
case 'TITLE':
// Book element - output closing row tag
echo '</p>', "\n";
break;
case 'URL':
// Title element - output closing bold and cell tags

break;

case 'LINK':
// Author or publisher element - output closing cell tag
echo '</font></p>', "\n";
break;

}
}
// Character data handler function
function characterData($parser, $value) {
// Trim any whitespace from the text (tabs, newlines)
$text = trim($value, "\t");
$text = trim($text, "\n");
$text = trim($text, "\r");
// Output the character data (text)
echo $text;
}
// Create a new instance of the XML parser
$parser = xml_parser_create();
// Set the handler functions
xml_set_element_handler($parser, 'startElement', 'endElement');
xml_set_character_data_handler($parser, 'characterData');
// Open the XML file
if ($file = @fopen($file_name, 'r')) {
// Loop through the file and parse XML
while ($data = fgets($file, 4096)) {
// If there was an error with the parsing
if (!xml_parse($parser, $data, feof($file))) {
// Show an error message
die('<p><b>XML parsing error.</b></p>');
}
}
// Close the file
fclose($file);
// File couldn't be opened
} else {
// Show an error message
die('<p>Could not open file <b>'.$file_name.'</b>.</p>');
}
// Free the parser instance
xml_parser_free($parser);
?>


Este codigo anda perfecto, pero l oque quuiero haces, es por ejemplo que por cada linea, se conecte a una base de datos y compare si esa linea esta en dicha base, sino esta se agrega. Podrian darme una orientacion? Nose como agarrar la cadena por ejemplo lo que va a insertar que esta entrer ´title´ del xml y pasarla a una variable. Me explico?

Muchas Gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:20.