j'ai besoin de l'aide.
Je veux changer le contenu d'un noeud en utilisant replaceChild.
Voici mon code :
il m'affiche cet erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 function replacingNode($currentNode, $node) { $node->parentNode->replaceChild($currentNode, $node); } $action = $_POST['action']; $updateRecordsArray = $_POST['recordsArray']; if ($action == "updateRecordsListings"){ $i=0; foreach ($updateRecordsArray as $recordIDValue) { // Load the XML $dom = new DomDocument; $dom->load("album.xml"); //This function replaces $currentNode with $node $piece=explode(":",$recordIDValue); $url=$piece[0]; $titre=$piece[1]; $nomFoto=$piece[2]; $idalbum=$piece[3]; $idgal=$piece[4]; $idFoto=$piece[5]; $xml = simplexml_load_file('album.xml'); $nodeurl = $xml->xpath("/albums/album[@idAlbum]/galeries/galerie[@idGal]/photos/photo/url/text()"); $oldnode = $nodeurl->item($idFoto); $text = $dom->createTextNode($url); $oldnode->parentNode->replaceChild($text, $oldnode); $i++; $xmlTmpl = $dom->save("album.xml"); } }
Fatal error: Call to a member function item() on a non-object in Cocuments and SettingsAdministrateurBureauCopie de projet_gallerieupdatexml.php on line 32
Mon fichier xml est le suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <albums> <album idAlbum="0"> <nomAlbum>Mode</nomAlbum> <galeries> <galerie idGal="0"> <dateDeModifAlbum>09-09-18</dateDeModifAlbum> <nom>gal1</nom> <legendeAlbum>legende1</legendeAlbum> <photos> <photo idFoto="0"><dateDeMotif>2009-09-29</dateDeMotif><nomFoto>allo1</nomFoto><url>Mode/photos/ddleop.jpg</url><titre>test3</titre><dateDeCreaFoto>2009-09-29</dateDeCreaFoto></photo> <photo idFoto="1"><dateDeMotif>2009-09-30</dateDeMotif><nomFoto>allo2</nomFoto><url>Mode/photos/pageLogin.jpg</url><titre>page1</titre><dateDeCreaFoto>2009-09-30</dateDeCreaFoto></photo> <photo idFoto="2"><dateDeMotif>2009-09-30</dateDeMotif><nomFoto>allo3</nomFoto><url>Mode/photos/pageMessages.jpg</url><titre>page2</titre><dateDeCreaFoto>2009-09-30</dateDeCreaFoto></photo> <photo idFoto="3"><dateDeMotif>2009-09-30</dateDeMotif><nomFoto>allo4</nomFoto><url>Mode/photos/pqgeBoiteReception.jpg</url><titre>page3</titre><dateDeCreaFoto>2009-09-30</dateDeCreaFoto></photo> </photos> </galerie> </galeries> </album> </albums>
Partager