DOMDocumentFragment can be very useful with XPath: you may need to apply an XPath expression to a list of nodes.
$dom_doc = new DOMDocument();
$dom_fragment = $dom_doc->createDocumentFragment();
$dom_element_a1 = $dom_fragment->appendChild($dom_doc->createElement('a', 'first node'));
$dom_element_a2 = $dom_fragment->appendChild($dom_doc->createElement('a', 'second node'));
$xpath = new DOMXpath($dom_doc);
$nodes = $xpath->query('a', $dom_fragment);
foreach ($nodes as $node) {
echo $node->textContent . "\n";
}
This way you do not need to embed the nodes within a parent element that could be returned by the xpath expression when you do not want this to happen.