Ok, so your solution.
For a DIV:
<div id="divID" name="notWorking">This is not working!</div>
This will do:
<?php
$dom = new DOMDocument("1.0", "utf-8");
$dom->loadHTMLFile('YourFile.html');
$div = $dom->getElementById('divID');
echo $div->textContent;
$div->setAttribute("name", "yesItWorks");
?>
Should work without the file as long as you pass a Well-Made XML or XHTML content, changing
$dom->loadHTMLFile('YourFile.html');
to your
$dom->loadHTML($html);
Oh yeah, and of course, to CHANGE the content (For completeness):
$div->removeChild($div->firstChild);
$newText = new DOMText('Yes this works!');
$div->appendChild($newText);
Then you can just Echo it again or something.