I have several identical elements with different attributes that I\'m accessing with SimpleXML:
If you extend the base SimpleXMLElement class, you can use this method:
class MyXML extends SimpleXMLElement {
public function find($xpath) {
$tmp = $this->xpath($xpath);
return isset($tmp[0])? $tmp[0]: null;
}
public function remove() {
$dom = dom_import_simplexml($this);
return $dom->parentNode->removeChild($dom);
}
}
// Example: removing the element with id = 1
$foo = new MyXML(' ');
$foo->find('//bar[@id="1"]')->remove();
print $foo->asXML(); //