I have what should be an easy task: delete <places> nodes and their descendants from an XML document, leaving other nodes.
I tried this code, but it did not work …
$document->preserveWhiteSpace = false;
$books = $xpath->query('piletilve_info/places');
//echo "4";
foreach ($books as $places) {
while($places->hasChildNodes()) {
$places->removeChild($places->childNodes->item(0));
}
$places->parentNode->removeChild($places);
}
Source XML to be processed:
<piletilve_info>
<places>
<place>
...
</place>
</places>
<other node>
...
</other node>
</piletilve_info>
In the actual data there are more nodes that aren’t places, but for simplicity this example shows only a few.
I saw C# examples, but I do not manage to port code to PHP.
Clarification : in code snippet, the variable $books is just a holder for the queried list. The name has no meaning.
will remove all
<places>elements anywhere in the document, including any children.Output: