**mUs3**
29-03-2007, 00:57
Premetto che non sono molto esperto in php..
E' un pò si tempo che sclero su questa cosa...
Devo poter editare un file xml che serve da feed per un podcasting...
Come noto, la struttura standard per un feed podcast è:
<rss version="2.0">
<channel>
<title>Titolo del podcast</title>
<link>http://www.indirizzodominio.it</link>
<description>Descrizione del podcast</description>
<language>it</language>
<copyright>Autore</copyright>
<managingEditor>indirizzo@nomedominio.it</managingEditor>
<webMaster>webmaster@nomedominio</webMaster>
<pubDate>Tue, 30 May 2006 22:042:00 GMT</pubDate>
<lastBuildDate>Tue, 30 May 2006 22:042:00 GMT</lastBuildDate>
<docs>http://www.nomedominio.it/pagina.html</docs>
<item>
<title>Titolo</title>
<file>titolo.mp3</file>
<link>http://www.nomedominio.it/titolo.mp3</link>
<description>Descrizione</description>
<author>Autore</author>
<enclosure url="http://www.nomedominio.it/titolo.mp3" length="1234567890" type="audio/mpeg">http://www.nomedominio.it/titolo.mp3</enclosure>
<pubDate>Tue, 30 May 2006 22:042:00 GMT</pubDate>
<source url="http://www.nomedominio.it/titolo.mp3">http://www.nomedominio.it/titolo.mp3</source>
</item>
</channel></rss>
La funzione che uso per inserire nuovi item è :
// Costruzione del feed //
//load file into $fc array
$fc=file("$podcast");
//open same file and use "w" to clear file
$f=fopen("$podcast","w");
//loop through array using foreach
foreach($fc as $line)
{
if (!strstr($line,$key)) //look for $key in each line
fputs($f,$line); //place $line back in file
}
// make feed //
$feed="<item>\n<title>".$title."</title>\n<link>".$link."</link>\n<file>".$file."</file>\n<description>".$desc."</description>\n<author>".$auth.'</author>'."\n".'<enclosure url="'.$link.'" length="'.$lenght.'" type="'.$type.'">'.$link."</enclosure>\n<pubDate>".$pubDate.'</pubDate>'."\n".'<source url="'.$link.'">'.$link.'</source>'."\n</item>\n</channel></rss>";
fwrite($f,$feed);
fclose($f);
e fin qui tutto bene, il problema nasce quando cerco di rimuovere un item con questa funzione :
// Rimozione del feed //
foreach ($_POST['delete'] as $file) {
$streamfile = new DomDocument();
$streamfile->load($podcast);
//cerca il file da cancellare //
$sstream = simplexml_load_file($podcast);
$count = 0;
$streamer=$sstream->channel;
foreach($streamer->item as $filename) {
if ($filename->file == $file) {
$streamfile->documentElement->removeChild($streamfile->documentElement->childNodes->item($count));
$count--;
}
$count++;
}
$streamfile->save($podcast);
echo $title." rimosso con successo.<br/>";
}
}
else echo "Errore durante la rimozione del feed."
E' una funzione che uso già con altri xml con struttura di tipo:
<item>
<child></child>
</item>
ma con la struttura "asimmetrica" del feed podcast a quanto pare fa casini :(
grazie per l'attenzione
:help: :muro:
E' un pò si tempo che sclero su questa cosa...
Devo poter editare un file xml che serve da feed per un podcasting...
Come noto, la struttura standard per un feed podcast è:
<rss version="2.0">
<channel>
<title>Titolo del podcast</title>
<link>http://www.indirizzodominio.it</link>
<description>Descrizione del podcast</description>
<language>it</language>
<copyright>Autore</copyright>
<managingEditor>indirizzo@nomedominio.it</managingEditor>
<webMaster>webmaster@nomedominio</webMaster>
<pubDate>Tue, 30 May 2006 22:042:00 GMT</pubDate>
<lastBuildDate>Tue, 30 May 2006 22:042:00 GMT</lastBuildDate>
<docs>http://www.nomedominio.it/pagina.html</docs>
<item>
<title>Titolo</title>
<file>titolo.mp3</file>
<link>http://www.nomedominio.it/titolo.mp3</link>
<description>Descrizione</description>
<author>Autore</author>
<enclosure url="http://www.nomedominio.it/titolo.mp3" length="1234567890" type="audio/mpeg">http://www.nomedominio.it/titolo.mp3</enclosure>
<pubDate>Tue, 30 May 2006 22:042:00 GMT</pubDate>
<source url="http://www.nomedominio.it/titolo.mp3">http://www.nomedominio.it/titolo.mp3</source>
</item>
</channel></rss>
La funzione che uso per inserire nuovi item è :
// Costruzione del feed //
//load file into $fc array
$fc=file("$podcast");
//open same file and use "w" to clear file
$f=fopen("$podcast","w");
//loop through array using foreach
foreach($fc as $line)
{
if (!strstr($line,$key)) //look for $key in each line
fputs($f,$line); //place $line back in file
}
// make feed //
$feed="<item>\n<title>".$title."</title>\n<link>".$link."</link>\n<file>".$file."</file>\n<description>".$desc."</description>\n<author>".$auth.'</author>'."\n".'<enclosure url="'.$link.'" length="'.$lenght.'" type="'.$type.'">'.$link."</enclosure>\n<pubDate>".$pubDate.'</pubDate>'."\n".'<source url="'.$link.'">'.$link.'</source>'."\n</item>\n</channel></rss>";
fwrite($f,$feed);
fclose($f);
e fin qui tutto bene, il problema nasce quando cerco di rimuovere un item con questa funzione :
// Rimozione del feed //
foreach ($_POST['delete'] as $file) {
$streamfile = new DomDocument();
$streamfile->load($podcast);
//cerca il file da cancellare //
$sstream = simplexml_load_file($podcast);
$count = 0;
$streamer=$sstream->channel;
foreach($streamer->item as $filename) {
if ($filename->file == $file) {
$streamfile->documentElement->removeChild($streamfile->documentElement->childNodes->item($count));
$count--;
}
$count++;
}
$streamfile->save($podcast);
echo $title." rimosso con successo.<br/>";
}
}
else echo "Errore durante la rimozione del feed."
E' una funzione che uso già con altri xml con struttura di tipo:
<item>
<child></child>
</item>
ma con la struttura "asimmetrica" del feed podcast a quanto pare fa casini :(
grazie per l'attenzione
:help: :muro: