php - Call to a member function appendChild() on a non-object in -


what wrong code ?

public function openxml() {     // ouverture du fichier     $file = new domdocument();     $file->load("lastitems.xml");       //on retourne le fichier     return $file; }  public function createxml() {     // création du fichier en mémoire      $file = new domdocument("1.0");      // création du noeud racine     $root = $file->createelement("rss"); //on crée l élément racine     $root->setattribute("version", "2.0"); //on lui ajoute l attribut version (2.0)     $root = $file->appendchild($root); //on insère la racine dans le document      // création du noeud channel      $element_channel = $file->createelement("channel");//on crée un élément channel     $element_channel->setattribute("id", "lastitem"); //on donne un attribut id à notre channel     $element_channel = $root->appendchild($element_channel);//on ajoute cet élément à la racine      // création du noeud description      $element_description = $file->createelement("description");//on crée un élément description     $element_description = $element_channel->appendchild($element_description);//on ajoute cet élément au channel      // création du texte pour le noeud description      $texte_description = $file->createtextnode("last 10 items in vsook"); //on crée un texte     $texte_description = $element_description->appendchild($texte_description); //on insère ce texte dans le noeud description      // création du noeud link et ajout du texte à l élément      $element_link = $file->createelement("link");     $element_link = $element_channel->appendchild($element_link);     $texte_link = $file->createtextnode("http://www.mysite.com/");     $texte_link = $element_link->appendchild($texte_link);      // création du noeud title et ajout du texte à l élément      $element_title = $file->createelement("title");     $element_title = $element_channel->appendchild($element_title);     $texte_title = $file->createtextnode("rss items");     $texte_title = $element_title->appendchild($texte_title);      //on retourne le fichier xml     return $file; }  public function addonenews($file, $title, $timestamp, $author) {     //on récupère le channel     $element_channel = $file->getelementbyid("lastitem");      // création du noeud item     $element_item = $file->createelement("item");     $element_item = $element_channel->appendchild($element_item);      // création du noeud title et ajout du texte à l élément      $element_title = $file->createelement("title");     $element_title = $element_item->appendchild($element_title);     $texte_title = $file->createtextnode($title);     $texte_title = $element_title->appendchild($texte_title);      // création du noeud link et ajout du texte à l élément      $element_link = $file->createelement("link");     $element_link = $element_item->appendchild($element_link);     $texte_link = $file->createtextnode("lien vers la news");     $texte_link = $element_link->appendchild($texte_link);      // création du noeud pubdate et ajout du texte à l élément      $element_date = $file->createelement("pubdate");     $element_date = $element_item->appendchild($element_date);     $texte_date = $file->createtextnode($date("d/m/y h:i",$timestamp));     $texte_date = $element_date->appendchild($texte_date);      // création du noeud author et ajout du texte à l élément      $element_author = $file->createelement("author");     $element_author = $element_item->appendchild($element_author);     $texte_author = $file->createtextnode($author);     $texte_author = $element_author->appendchild($texte_author); } public function savexml($file) {     //sauvegarde du fichier     $file->save("lastitems.xml"); } 

when use error :

fatal error: call member function appendchild() on non-object in c:\wamp\www\mysite\includes\querys.php on line 1604

line 1604 :

$file->getelementbyid("lastitem");

this simple function create , generate xml rss file.

well, without knowing line numbers are, impossible know sure, bet line:

$file->getelementbyid("lastitem"); 

are sure there element id="lastitem"?

unless put comment in , tell actual line number, suspect won't better.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -