Re: AW: appendChild() something I fail to understand
Brought to you by:
bs_php,
nigelswinson
From: Luc Saint-E. <lu...@sa...> - 2002-01-17 13:26:03
|
Hello, Still in my "lets's learn toproduce xml files process", my problem is solved (thanks Jan) with attributes but now I fail when I want to ad nodes. The goal now is to ad a new message in the messages.xml file. a message is of the form : <liste> <message> <is_read>no</is_read> <texte>text of the message</texte> <expediteur>username_of_the_sender</expediteur> <destinataire>usernameof the destination</destinataire> <date>1011272580</date> </message> </liste> With the following bit of code the entry is done, but a lot of errors are sent like : *************** XPath error in XPath.class.php:4659 The /liste[1]/message[4]/is_read[1] does not have a text node at position 0 XPath error in XPath.class.php:4659 The /liste[1]/message[4]/texte[1] does not have a text node at position 0 XPath error in XPath.class.php:4659 The /liste[1]/message[4]/expediteur[1] does not have a text node at position 0 XPath error in XPath.class.php:4659 The /liste[1]/message[4]/destinataire[1] does not have a text node at position 0 XPath error in XPath.class.php:4659 The /liste[1]/message[4]/date[1] does not have a text node at position 0 **************** here is my code case 'newmsgs' :$xPath->reset(); $xPath->importFromFile('xml_files/messages.xml'); $newchild=$xPath->appendChild('/liste[1]', 'message'); $newchild1=$xPath->appendChild($newchild, 'is_read'); $xPath->insertData($newchild1, 'no'); $newchild2=$xPath->appendChild($newchild, 'texte'); $xPath->insertData($newchild2, $texte); $newchild3=$xPath->appendChild($newchild, 'expediteur'); $xPath->insertData($newchild3, $expediteur); $newchild4=$xPath->appendChild($newchild, 'destinataire'); $xPath->insertData($newchild4, $destinataire); $newchild5=$xPath->appendChild($newchild, 'date'); $xPath->insertData($newchild5, time()); $xPath->exportToFile('xml_files/messages.xml','','<?xml version="1.0" encoding="iso-8859-1"'.'?'.'>'); Thanks in advance (and tons of excuses for my dummy questions) Luc |