从XML节点PHP DOM中删除所有的孩子 [英] Remove all children from a XML Node PHP DOM

查看:115
本文介绍了从XML节点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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆