I\'m trying to remove the \"druzenje\" element by the \'id\' attribute. I know that for that to happen, i have to remove all the child nodes from that element.
&
Someone kill me. I haven't been saving. I apologize for wasting someone's precious time.
$element = $this->dom->getElementById($id);
$element->parentNode->removeChild($element);
getElementsByTagName() returns "live" result that you remove the elements from the DOM. Copy it to an array to get a fixed list.
$druzenja = iterator_to_array(
$this->dom->getElementsByTagName('druzenje')
);
foreach ($druzenja as $node) {
if ($node->getAttribute('id') == $id) {
$node->parentNode->removeChild($node);
}
}
Xpath would allow you to use more complex conditions. The result is not live.
$xpath = new DOMXpath($this->dom);
foreach ($xpath->evaluate('//druzenje[@id="'.$id.'"]') as $node) {
$node->parentNode->removeChild($node);
}