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


i want use dom removechild function in php remove between tag.

my xml looks like

<root>   <element>text</element>    <remove>     text     <morexml>text</morexml>   </remove> </root> 

now want remove tag including entire inside. how do this? not have clue. trying use dom function found: removechild.

when removed has this:

 <root>       <element>text</element>   </root> 

is there php dom function this? can not find on google or stackoverflow.

$dom = new domdocument; $dom->loadxml($xml); $dom->getelementsbytagname('root')->item(0)    ->removechild($dom->getelementsbytagname('remove')->item(0)); 

this specific, though. can use xpath if need more generality:

foreach ($xpath->query('//remove') $node) {    $node->parentnode->removechild($node); } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -