Remove all children from a XML Node PHP DOM

Viewed 11403

I want to remove all children from a XML Node using PHP DOM, is there any difference between:

A)

while ($parentNode->hasChildNodes()){
   $parentNode->removeChild($parentNode->childNodes->item(0));
 }

AND

B)

$node->nodeValue = "";

I prefer the second one, seems like I am getting the same result but I'm not sure.

Thanks, Carlos

2 Answers

Slightly tighter:

  while ($parentNode->hasChildNodes()) {
    $parentNode->removeChild($parentNode->firstChild);
  }
Related