[DOM XML] Supprimer un noeud de ma base XML chargé avec un DomDocument
Voici mon code :
Code:
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 :
Citation:
« 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:
1 2
| $firstChild = $domxml->getElementsByTagName('Product')->item(0);
$child=$domxml->removeChild($firstChild) ; // Ligne 156 |
Le bô résultat est :
Citation:
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) :yaisse2::
Code:
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&f=28&t=.mp3</Localization>
<Caption>Disturbia</Caption>
<CommandUrl>http://kifetonmobile.magikmobile.com/culture/fr-FR/popup-redirect.aspx?q5=863455&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&f=28&t=.mp3</Localization>
<Caption>Right now (na na na)</Caption>
<CommandUrl>http://kifetonmobile.magikmobile.com/culture/fr-FR/popup-redirect.aspx?q5=885647&p=21</CommandUrl>
<ProductType>Sonnerie poly</ProductType>
<ProductTypeId>21</ProductTypeId>
<Interpret>Akon</Interpret>
</Product>
</ArrayOfProduct> |