note 66042 added to function.dom-domdocument-createdocumentfragment

From: Date: Sat, 13 May 2006 03:04:12 +0000
Subject: note 66042 added to function.dom-domdocument-createdocumentfragment
Groups: php.notes 
Request: Send a blank email to php-notes+get-111203@lists.php.net to get a copy of this message
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. ---- Server IP: 193.190.198.20 Probable Submitter: 87.65.161.137 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-createdocumentfragment.php Edit -- http://master.php.net/note/edit/66042 Del: integrated -- http://master.php.net/note/delete/66042/integrated Del: useless -- http://master.php.net/note/delete/66042/useless Del: bad code -- http://master.php.net/note/delete/66042/bad+code Del: spam -- http://master.php.net/note/delete/66042/spam Del: non-english -- http://master.php.net/note/delete/66042/non-english Del: in docs -- http://master.php.net/note/delete/66042/in+docs Del: other reasons-- http://master.php.net/note/delete/66042 Reject -- http://master.php.net/note/reject/66042 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111203) next »