note 63736 modified in function.simplexml-element-xpath by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Sep 2009 15:53:47 +0000 |
| Subject: | note 63736 modified in function.simplexml-element-xpath by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160692@lists.php.net to get a copy of this message | ||
xpath returning references to the parent simplexml object can bite you performance wise when
processing large trees.
this bit me big time so looking for a solution I came up with a simple way to speed up the code.
'dereferencing' will yield instant results, code will be lighting fast.
sacrifice is losing the reference to the parent object, for simple read-only operation this should
be ok.
<?php
$data = 'data.xml';
$rs = simplexml_load_file($data);
foreach($rs->xpath('//row') as $rsrow){
// 'derefence' into a seperate xml tree for performance
$row = simplexml_load_string($rsrow->asXML());
$v = $row->xpath('//field[@name="id"]');
}
?>
--was--
xpath returning references to the parent simplexml object can bite you performance wise when
processing large trees.
this bit me big time so looking for a solution I came up with a simple way to speed up the code.
'dereferencing' will yield instant results, code will be lighting fast.
sacrifice is losing the reference to the parent object, for simple read-only operation this should
be ok.
<?php
$data = 'data.xml';
$rs = simplexml_load_file($data);
foreach($rs->xpath('//row') as $rsrow){
// 'derefence' into a seperate xml tree for performance
$row = simplexml_load_string($rsrow->asXML());
$v = $row->xpath('//field[@name="id"]');
}
?>
http://php.net/manual/en/function.simplexml-element-xpath.php