private function loadFragmentIntoDom(\DOMDocument $document, $source, $loadOptions) { $htmlDom = new Document(); $htmlDom->loadHTML('<html-fragment>' . $source . '</html-fragment>', $loadOptions); $nodes = $htmlDom->evaluate('//html-fragment[1]/node()'); foreach ($nodes as $node) { if ($importedNode = $document->importNode($node, TRUE)) { $document->appendChild($importedNode); } } }