IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[DOM XML] Supprimer un noeud de ma base XML chargé avec un DomDocument


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre régulier Avatar de youtch
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    94
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations forums :
    Inscription : Septembre 2002
    Messages : 94
    Points : 90
    Points
    90
    Par défaut [DOM XML] Supprimer un noeud de ma base XML chargé avec un DomDocument
    Voici mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    $domxml = new DomDocument();
    $domxml->load('GetProducts.xml'); 
    $items = $domxml->getElementsByTagName('Product');
     
    $taille_items=$items->length;
    $monxml=array(); $nb_items=0 ; 
    $page_max=ceil(count($items)/$nb_max_items) ;
    if($num_page>=1) 
    	{ $firstChild=$items->item(0);  // correspondrait à 'ArrayOfProduct->Product n°863455 ' (Disturbia de Rihanna) ... et tous ses fils 
    	   $items->removeChild($firstChild); // C'est là que ça cloche (ligne 151)
    	}
    Invariablement, j'ai une jolie erreur :
    « Fatal error: Call to undefined method DOMNodeList::removeChild() in E:\Mes documents\Apache www\Magic_Mobile\prod\sonneries.php5 on line 151 »
    Pas découragé, j'essaie autre chose pour la conditionnelle IF...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $firstChild = $domxml->getElementsByTagName('Product')->item(0); 
    $child=$domxml->removeChild($firstChild) ; // Ligne 156
    Le bô résultat est :
    Fatal error: Uncaught exception 'DOMException' with message 'Not Found Error' in E:\Mes documents\Apache www\Magic_Mobile\prod\sonneries.php5:156 Stack trace: #0 E:\Mes documents\Apache www\Magic_Mobile\prod\sonneries.php5(156): DOMNode->removeChild(Object(DOMElement)) #1 {main} thrown in E:\Mes documents\Apache www\Magic_Mobile\prod\sonneries.php5 on line 156
    LE tout en essayant de suivre la doc d'un tuto de developpez.com, ainsi que la doc officielle de PHP ... suis-je réellement un cancre en DomXML ?? Je précise que j'utiliser PHP5.2.0 et Apache 2 ,

    merci d'avance.

    Voici aussi mon fichier XML (que j'ai un peu raccourci pour simplifier) :
    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
    <?xml version="1.0" encoding="utf-8"?>
    <ArrayOfProduct xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sonnerie.com">
      <Product Id="863455">
        <Localization>http://content.mkmb.net/p.ashx?id=863455&amp;f=28&amp;t=.mp3</Localization>
        <Caption>Disturbia</Caption>
        <CommandUrl>http://kifetonmobile.magikmobile.com/culture/fr-FR/popup-redirect.aspx?q5=863455&amp;p=21</CommandUrl>
        <ProductType>Sonnerie poly</ProductType>
        <ProductTypeId>21</ProductTypeId>
        <Interpret>Rihanna</Interpret>
      </Product>
      <Product Id="885647">
        <Localization>http://content.mkmb.net/p.ashx?id=885647&amp;f=28&amp;t=.mp3</Localization>
        <Caption>Right now (na na na)</Caption>
        <CommandUrl>http://kifetonmobile.magikmobile.com/culture/fr-FR/popup-redirect.aspx?q5=885647&amp;p=21</CommandUrl>
        <ProductType>Sonnerie poly</ProductType>
        <ProductTypeId>21</ProductTypeId>
        <Interpret>Akon</Interpret>
      </Product>
    </ArrayOfProduct>
    Si personne ne répond à votre question, c'est peut-être parce qu'il n'y a pas de solution

  2. #2
    Expert éminent sénior

    Profil pro
    Inscrit en
    Juin 2002
    Messages
    6 152
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 6 152
    Points : 17 778
    Points
    17 778
    Par défaut
    Essayez de remplacer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $items->removeChild($firstChild);
    Par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $firstChild->parentNode->removeChild($firstChild);
    Car, en effet, la classe DOMNodeList ne définit pas de méthode removeChild mais DOMNode, oui.

    Ici il ne s'agit pas de l'extension DOMXML (PHP 4) mais bien DOM (PHP 5).

  3. #3
    Membre régulier Avatar de youtch
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    94
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations forums :
    Inscription : Septembre 2002
    Messages : 94
    Points : 90
    Points
    90
    Par défaut
    Merci bien, ça marche !!!
    Si personne ne répond à votre question, c'est peut-être parce qu'il n'y a pas de solution

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. xml:supprimer un noeud avec dom
    Par awalter1 dans le forum Général Python
    Réponses: 1
    Dernier message: 27/10/2010, 16h01
  2. [XML] [DOM XML] editer un noeud dans un fichier XML
    Par nina.b dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 17/09/2009, 13h22
  3. [DOM] Supprimer un noeud d'un fichier XML
    Par popy67 dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 09/06/2008, 23h22
  4. [DOM] supprimer un noeud XML
    Par hicham285 dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 12/04/2008, 21h28
  5. [XML DOM]Supprimer plusieurs noeud
    Par Shandler dans le forum APIs
    Réponses: 9
    Dernier message: 06/06/2007, 20h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo