How to remove all xml children with a given element name in PHP with SimpleXML?
<xml>
<computer></computer>
<book></book>
<book></book>
</xml>
I need a quick way to remove all "book" elements. Thanks!
How to remove all xml children with a given element name in PHP with SimpleXML?
<xml>
<computer></computer>
<book></book>
<book></book>
</xml>
I need a quick way to remove all "book" elements. Thanks!
select all nodes with xpath
and unset
them:
$xml = simplexml_load_string($x); // assume XML in $x
$books = $xml->xpath("//book");
foreach ($books as $book) unset($book[0]);
see it in action: https://eval.in/105257