I\'m working on a small templating engine, and I\'m using DOMDocument to parse the pages. My test page so far looks like this:
Nothing: nodeValue is the concatenation of the value portion of the tree, and will never have tags.
What I would do to make an HTML fragment of the tree under $node is this:
$doc = new DOMDocument();
foreach($node->childNodes as $child) {
$doc->appendChild($doc->importNode($child, true));
}
return $doc->saveHTML();
HTML "fragments" are actually more problematic than you'd think at first, because they tend to lack things like doctypes and character sets, which makes it hard to deterministically go back and forth between portions of a DOM tree and HTML fragments.