$code = \'
Galeria
-
You might consider DOMDocumentFragment rather than DOMDocument if you don't want headers.
As for the id problem, this is from the manual:
validateOnParse = true;
$doc->Load('book.xml');
echo "The element whose id is books is: " . $doc->getElementById('books')->tagName . "\n";
?>
validateOnParse is likely the issue.