[PHP/DOM]remove a XML node itself

We can remove a child node in Dom by php (example from php.nex):

$doc = new DOMDocument;

$book = $doc->documentElement;

// we retrieve the chapter and remove it from the book
$chapter = $book->getElementsByTagName('chapter')->item(0);
$oldchapter = $book->removeChild($chapter);

echo $doc->saveXML();

But if you want to delete the node itself, you could do something like this, it will delete the first appearance of the node:

$dom = new DomDocument();
$doc = $dom->loadXML($strXml);
$tagName = $dom->getElementsByTagName('tagName')->item(0);
echo $dom->saveXML();