![Negando](http://static.forosdelweb.com/fdwtheme/images/smilies/negar.gif)
![dormir](http://static.forosdelweb.com/fdwtheme/images/smilies/durmiendo.png)
![Adios](http://static.forosdelweb.com/fdwtheme/images/smilies/adios.gif)
<?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