note 105531 added to domxpath.query

From: Date: Thu, 25 Aug 2011 07:18:02 +0000
Subject: note 105531 added to domxpath.query
Groups: php.notes 
Request: Send a blank email to php-notes+get-182712@lists.php.net to get a copy of this message
I'v write this: find all elements that: 1, Is descendant of context element 2, Have 'auto' attribute 3, Is highest level (have no ancestor between self and the context element) I'v implement it ,But I found the query is slowly, will someone make it faster? <?php $xml=' <root> <a auto="1" tempId="current"> <b> <c auto="1"> <d auto="1"></d> </c> </b> <e auto="1"> <f> <g auto="1"></g> </f> </e> </a> </root> '; $doc=new DomDocument(); $tempId='XDFAY69LA'; $doc->loadXml($xml); $domxpath=new DOMXPath($doc); $a=$domxpath->query('a')->item(0); $path=".//*[@auto and not(ancestor::*[@auto and ancestor::*[@tempId='$tempId']])]"; $start=microtime(true); for($n=0;$n<1000;$n++){ //run 1000 times $a->setAttribute('tempId',$tempId); $ar=$domxpath->query($path,$a); $a->removeAttribute('tempId'); for($i=0;$i<$ar->length;$i++){ $node=$ar->item($i); //echo $node->tagName . "\n"; } } $cost=round(1000 * (microtime(true)-$start)); echo "time cost: $cost"; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 123.186.242.58 ---- Manual Page -- http://www.php.net/manual/en/domxpath.query.php Edit -- https://master.php.net/note/edit/105531 Del: integrated -- https://master.php.net/note/delete/105531/integrated Del: useless -- https://master.php.net/note/delete/105531/useless Del: bad code -- https://master.php.net/note/delete/105531/bad+code Del: spam -- https://master.php.net/note/delete/105531/spam Del: non-english -- https://master.php.net/note/delete/105531/non-english Del: in docs -- https://master.php.net/note/delete/105531/in+docs Del: other reasons-- https://master.php.net/note/delete/105531 Reject -- https://master.php.net/note/reject/105531 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182712) next »