<?php
$html = '<div id="container">
<div id="test"></div>
<pre>
content
</pre>
</div>';
$dom = new DOMDocument;
$dom->loadXML($html);
$xpath = new DOMXPath($dom);
$query = '//div[@id="container"]/pre';
$entries = $xpath->query($query);
foreach($entries as $one){
$newelement = $dom->createTextNode('Some new node!');
$one->parentNode->replaceChild($newelement, $one);
}
echo $dom->saveHTML();