DOM Element doesn't delete all children

Question

I want to modify my XML in PHP and delete the SKU numbers from it.

I've tried this:

$dom = new DOMDocument();
$dom->load('data/onlinekeystore.xml');
$root = $dom->documentElement;

$skuMarker = $root->getElementsByTagName('sku');
for($i = 0; $i < $skuMarker->length; $i++){
    $sku = $skuMarker->item($i);
    $skuMarker->item($i)->parentNode->removeChild($sku);
}

but this is only deletes some of the children and not all! I also tried to loop backwards but if I use that no child will be deleted

for($i = $skuMarker->length - 1; $i = 0 ; $i--){
    $sku = $skuMarker->item($i);
    $skuMarker->item($i)->parentNode->removeChild($sku);
}

Show source
| php   | xml   | dom   2017-01-02 11:01 0 Answers

Answers ( 0 )

◀ Go back