XML ドキュメントからすべての子を削除できません
<?xml version="1.0" encoding="UTF-8"?>
<routes>
<route name="admin" />
<!---->
<route name="blog" bla bla/>
<route name="blog" bla bla/>
<route name="blog" bla bla/>
</routes>
$xml = simplexml_load_file('routes.xml');
$dom_sxe = dom_import_simplexml($xml); $dom = new \DOMDocument('1.0'); $dom_sxe = $dom->importNode($dom_sxe, true); $dom_sxe = $dom->appendChild($dom_sxe); foreach ($dom->getElementsByTagName('route') as $route) { if($route->getAttribute('name') === 'blog') { $route->parentNode->removeChild($route); echo $route->getAttribute('name'); } } echo $dom->saveXML();
属性blogを持つ 2 つの要素のみを削除します