note 66042 deleted from function.dom-domdocument-createdocumentfragment by danbrown

From: Date: Fri, 28 Nov 2008 21:20:01 +0000
Subject: note 66042 deleted from function.dom-domdocument-createdocumentfragment by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147230@lists.php.net to get a copy of this message
Note Submitter: jb at jbpros dot com ---- 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.

« previous php.notes (#147230) next »