Nada mejor que un ejemplo:
Código PHP:
<?php
$html=new DOMDocument();
$html->formatOutput=true;//les agrega tabulado para q se vea mas lindo
$body=$html->createElement("body");
$html->appendChild($body);
$div=$html->createElement("div");
$metotxt=$html->createTextNode("Div Generado con PHP mediante la creacion de un XML manipulado con DOM");
$div->appendChild($metotxt);
$div->setAttribute("id","php");
$div->setAttribute("style","-moz-border-radius:15px");
$body->appendChild($div);
echo $html->saveXML();
?>