Ciao a tutti,
Io ho questo codice per creare un file xml (in questo caso un feed rss)
Codice PHP:
$filename = "rss_avvisi/".$BACH.".xml";
// se non esiste il file per gli avvisi ne creo uno nuovo
if (!file_exists($filename)){
$handle = fopen($filename,"w") or die("Impossibile creare il file");
fclose($handle);
$domxml = domxml_new_doc("1.0");
$root = $domxml->append_child($domxml->create_element('rss'));
$root->set_attribute("version", "2.0");
$channel = $root->append_child($domxml->create_element('channel'));
$title = $channel->append_child($domxml->create_element('title'));
$title->append_child($domxml->create_text_node("PHYROSIA: Avvisi Bacheca $BACH"));
$link = $channel->append_child($domxml->create_element('link'));
$link->append_child($domxml->create_text_node("http://www.phyrosia.com"));
$lang = $channel->append_child($domxml->create_element('language'));
$lang->append_child($domxml->create_text_node("it"));
$domxml->dump_file($filename,false,true);
$domxml->free();
}
//in ogni caso aggiungo le nuove informazioni
$domxml = domxml_open_file($filename) or die("Impossibile aprire il file xml");
$root = $domxml->document_element();
$channel = $root->get_elements_by_tagname('channel');
$item_a = $channel[0]->get_elements_by_tagname('item');
while(count($item_a) > 10){
$last = $channel[0]->last_child();
$last->unlink_node();
$item_a = $channel[0]->get_elements_by_tagname('item');
}
$item = $channel[0]->append_child($domxml->create_element('item'));
$title = $item->append_child($domxml->create_element('title'));
$title->append_child($domxml->create_text_node("<![CDATA[Nuovo Messaggio in Bacheca $BACH]]>"));
$link = $item->append_child($domxml->create_element('link'));
$link->append_child($domxml->create_text_node("http://www.phyrosia.com/bacheche/vis_bacheca2.php?id_topic=$id_topic"));
$desc = $item->append_child($domxml->create_element('description'));
$desc->append_child($domxml->create_text_node("<![CDATA[$_SESSION[utente] ha scritto un nuovo messaggio in Bacheca $BACH]]>"));
$date = $item->append_child($domxml->create_element('pubDate'));
$date->append_child($domxml->create_text_node(date("r")));
$domxml->dump_file($filename,false,true);
$domxml->free();
ma mi dà un paio di problemi:
Il primo è che mi traduce <![CDATA[ in <![CDATA[
e ]]> in ]]>
Il secondo è che nonostante io metta "false,true" a tutti e due i dump_file, la formattazione me la fa solo sul primo dump_file. Infatti guardate com'è un esempio uscito da questo codice
codice:
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>PHYROSIA: Avvisi Bacheca Discussioni Admin</title>
<link>http://www.phyrosia.com</link>
<language>it</language>
<item><title><![CDATA[Nuovo Messaggio in Bacheca Discussioni Admin]]></title><link>http://www.phyrosia.com/bacheche/vis...?id_topic=4526</link><description><![CDATA[VoceDiVolcast ha scritto un nuovo messaggio in Bacheca Discussioni Admin]]></description><pubDate>Sat, 14 Mar 2009 11:30:15 +0100</pubDate></item><item><title><![CDATA[Nuovo Messaggio in Bacheca Discussioni Admin]]></title><link>http://www.phyrosia.com/bacheche/vis...?id_topic=4527</link><description><![CDATA[VoceDiVolcast ha scritto un nuovo messaggio in Bacheca Discussioni Admin]]></description><pubDate>Sat, 14 Mar 2009 11:31:00 +0100</pubDate></item></channel>
</rss>
qualcuno saprebbe gentilmente dirmi come posso risolvere? ^^;;
Grazie mille