Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > XML > DOM
DOM Forum d'entraide pour l'extension DOM permettant de manipuler des documents XML en PHP 5 (approche DOM). Avant de poster -> tutoriels DOM
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 24/08/2007, 10h55   #1
Rédacteur
 
Avatar de Yoshio
 
Homme
Inscription : septembre 2005
Messages : 1 741
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 24
Localisation : Belgique

Informations forums :
Inscription : septembre 2005
Messages : 1 741
Points : 1 497
Points : 1 497
Par défaut [DOM] Supprimer le dernier noeud

Bonjour,

Je cherche a supprimer le dernier noeud <entry>.

Voici la structure du xml :
Code XML :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://localhost/zf/public/</id>
  <entry>
    <id>6</id>
    <title>Test RSS1</title>
    <updated>2007-08-24T09:56:37+02:00</updated>
    <link href="http://localhost/"/>
  </entry>
  <entry>
    <id>7</id>
    <title>Test RSS 2</title>
    <updated>2007-08-24T09:56:51+02:00</updated>
    <link href="http://localhost/"/>
  </entry>
  <entry>
    <id>8</id>
    <title>Test RSS 3</title>
    <updated>2007-08-24T09:57:15+02:00</updated>
    <link href="http://localhost/"/>
  </entry>
</feed>


J'ai trouver une solution correct comme ceci :
Code :
1
2
3
4
5
6
7
8
9
10
11
// Load Xml
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->load('public/feed/news.xml');
 
$res = $dom->getElementsByTagName('entry');
$numFeed = $res->length - 1;
 
$entry = $dom->getElementsByTagName('entry')->item($numFeed);
$entry->parentNode->removeChild($entry);
C'est assez moche Est ce qu'il n'y a pas moyen d'utiliser un lastChild ? (j'ai pas trouver comment)


Yoshio
Yoshio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/08/2007, 11h14   #2
En attente de confirmation mail
 
Inscription : juin 2002
Messages : 6 164
Détails du profil
Informations forums :
Inscription : juin 2002
Messages : 6 164
Points : 6 404
Points : 6 404
Code :
$dom->documentElement->removeChild($dom->documentElement->lastChild);
ça ne suffit pas ?
julp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/08/2007, 11h18   #3
Rédacteur
 
Avatar de Yoshio
 
Homme
Inscription : septembre 2005
Messages : 1 741
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 24
Localisation : Belgique

Informations forums :
Inscription : septembre 2005
Messages : 1 741
Points : 1 497
Points : 1 497
C'est parfait
Yoshio est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h02.


 
 
 
 
Partenaires

Hébergement Web