2

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);
}
KhorneHoly
  • 4,666
  • 6
  • 43
  • 75
Jan
  • 179
  • 1
  • 1
  • 8
  • See this more detailed explanation as to why this is happening: http://stackoverflow.com/a/4616237/208809. Also, please fix your `$i=0` in the reverse for loop to a comparison (it's an assignment right now). **If this doesn't solve your problem, please provide a sample of the xml.** – Gordon Jan 02 '17 at 10:53
  • Oh yeah, that was the problem! ($i = 0) - Thank you! – Jan Jan 02 '17 at 11:41

0 Answers0