How to delete a element by tag name with all elements inside it

孤者浪人 提交于 2019-12-02 08:33:33
$dom = new DOMDocument;
$dom->loadXML($xml);
$dom->getElementsByTagName('root')->item(0)
   ->removeChild($dom->getElementsByTagName('remove')->item(0));

This is very specific, though. You can use XPath if you need more generality:

foreach ($xpath->query('//remove') as $node) {
   $node->parentNode->removeChild($node);
}
René Höhle

You can use XPath and delete over XPath the node.

Use DOM and XPath to remove a node from a sitemap file

PHP SimpleXML - Remove xpath node

here on Stackoverflow are a lot of posts. Perhaps you should search here at first.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!