tim cameron ryan ¶
14 years ago
Or something like:
pedro at leb dot usp dot br ¶
17 years ago
You may also use the hasChild function:
When you remove a childNode, the next node becomes the first one!
Vasil Rangelov ¶
14 years ago
At the time of writing, I suppose rightfully, removeChild[] removes only the selected node, but when you remove an element, it's child elements are not removed. If you want to achieve that, replaceChild[] is the solution.
The following should remove all descendants of the $node DOMNode, regardless of it's name:
If you're replacing the root element, you must explicitly state that with $node->documentElement as the second argument.
mytto at openxtrem dot com ¶
17 years ago
Back again on removing childs and iterators robustness.
Things get a bit more complicated when you only want to remove 'some' nodes according to a certain condition. Then you can't just remove the first one repeatedly.
The trick is to copy the content of the node list into a more robust collection than DOMNodeList, I name array!
The following piece of code will, for instance, remove all empty child nodes: