从XML节点PHP DOM中删除所有的孩子 [英] Remove all children from a XML Node PHP DOM
问题描述
我想使用PHP DOM从XML节点中删除所有的孩子,是否有区别:
A)
$ b $($ parentNode-> hasChildNodes()){
$ parentNode-> removeChild($ parentNode-> childNodes-> item(0))$ b
);
}
和
B)
$ node-> nodeValue =;
我更喜欢第二个,似乎我得到的结果相同,但我不确定。
谢谢,
Carlos
removeChild()
是更适当的做事方式。虽然您可以将该节点的内容设置为,这将获得所需的效果,调用
removeChild()
对于发生了什么更为明显。然而,这是我的假设,在微不足道的水平上, nodeValue()
的效率稍高一些。
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
removeChild()
is the more "proper" way of doing things. While you can set the contents of that node to ""
and this will acquire the desired effect, calling removeChild()
is much more apparent as to what is going on. However, it would be my assumption that, in a minuscule level, nodeValue()
is slightly more efficient.
这篇关于从XML节点PHP DOM中删除所有的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!