Ciao a tutti...ho un problema...ho un documento xml di cui riesco a visualizzare in parte gli elementi che lo contengono. Praticamente è un file nel quale inserisco notizie, delle quali riesco a visualizzare titolo, descrizione e link...ma non la data e non capisco perchè!?!?![]()
posto il codice del file php che crea il documento xml:
questo è invece il file che dovrebbe leggerlo...:Codice PHP:<?php
// Eseguo le operazioni di connessione al database MySQL
$connessione = mysql_connect("mysql5.netsons.org", "cisiamotutti", "ps231284")or die("Impossibile collegarsi al server MySQL.");
$db = mysql_select_db("cisiamotutti", $connessione)or die("Impossibile selezionare il database $dbname");
//faccio un controllo. Se non riesce a connettersi al db manda a video "unable to connect db".
if(!$db){
echo "unable to connect to db.";
exit;
}
else {
$selezionedati = "SELECT * FROM news ORDER BY ID DESC LIMIT 10";
$query = mysql_query($selezionedati) or die(mysql_error());
// Modifico l'intestazione e il tipo di documento da PHP a XML
header("Content-type: text/xml");
// Eseguo le operazioni di scrittura sul file
echo ("<rss version=\"2.0\">");
echo ("<channel>");
echo ("<title> News </title>");
echo("<link>[url]http://www.sito.com[/url]</link>");
echo ("<description> Descrizione News </description>");
echo "<copyright>Copyright 2008 Mio sito.com </copyright>\n";
echo "<docs>[url]http://blogs.law.harvard.edu/tech/rss[/url]</docs>\n";//Documentazione rss
echo "<managingEditor>miamail@miosito.com</managingEditor>\n";
echo "<webMaster>miamail@miosito.com</webMaster>\n";
echo ("<language>IT-it</language>");
while($array = mysql_fetch_array($query)){
extract($array);
echo "<item>
<title>$TITOLO</title>
<date>$WHENADDED</date>
<link>[url]http://www.miosito.com/leggi.php?ID=[/url]$ID</link>
<description>$DESCRIZIONE</description>
</item>";
}
echo "</channel></rss>";
}
?>
beh...mi visualizza $notizia, $descrizione, $titolo, ma non $date...e non capisco il perchè?...qualcuno mi riesce a dire cosa c'è che non va?Codice PHP:<?php
class XmlLoader {
public $doc = null;
public function __construct() {
$this->doc = new DOMDocument();
}
public function loadXmlFile($fileName) {
if(!$this->doc->load($fileName)) {
throw new Exception('Error loading file ['.$fileName.']');
}
return new XmlParser($this->doc);
}
}//
class XmlParser
{
public $doc = null;
public function __construct($doc) {
$this->doc = $doc;
}
public function save($fileName) {
if(!$this->doc->save($fileName)){
throw new Exception('Error saving file ['.$fileName.']');
}
}
//rss
public function getDocumentElement()
{
return $this->doc->documentElement;
}
//item
public function getItems()
{
return $this->getDocumentElement()->getElementsByTagName("item");
}
}//
try{
$doc = new XmlLoader();
$docXmlParser = $doc->loadXmlFile('http://www.cisiamotutti.netsons.org/rss.php');
//get all items returns a DomNodeList
$elements=$docXmlParser->getDocumentElement()->getElementsByTagName("item");
foreach($elements as $node) {
$date=$node->getElementsByTagName("date");
$title=$node->getElementsByTagName("title");
$news=$node->getElementsByTagName("description");
$link=$node->getElementsByTagName("link");
foreach($title as $notizia){
foreach($news as $descrizione){
foreach($link as $titolo){
?>
</p>
<table width="100%" border="1">
<tr>
<td><span class="Stile6"><?php print $date->textContent."\n";
?></span></td>
</tr>
<tr>
<td><span class="Stile6"><?php print $notizia->textContent."\n";
?></span></td>
</tr>
<tr>
<td><span class="Stile6"><?php print $descrizione->textContent."\n";
?></span></td>
</tr>
<tr>
<td><span class="Stile6">[url="<?php print $titolo->textContent."]"> Vedi tutto[/url]</span></td>
</tr>
</table>
<?php
}}
}
}
}
catch(Exception $e){
echo $e->getMessage();
exit();
}
?>

Rispondi quotando
...non mi risponde nessuno...è tanto complicato quel codice?
