note 89258 deleted from function.simplexml-element-xpath by danbrown

From: Date: Sat, 28 Feb 2009 17:26:37 +0000
Subject: note 89258 deleted from function.simplexml-element-xpath by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151255@lists.php.net to get a copy of this message
Note Submitter: remy dot damour at -please-no-spam-laposte dot net ---- Warning, as Hugh already wrote below, ->xpath() does not always return an array, sometimes it returns boolean 'false' => be carefull prior to looping through xpath result Example: <?php $string = <<<XML <a> <b> <c>text</c> <c>stuff</c> </b> <d> <c>code</c> </d> </a> XML; $xml = new SimpleXMLElement($string); /* Search for non-existing path WITHOUT specifying namespace */ $result = $xml->xpath('//x/y'); var_dump($result); // array(0) {} /* Search for non-existing path SPECIFYING namespace */ $xml->registerXPathNamespace('default', 'foo'); $result = $xml->xpath('//default:x/default:y'); var_dump($result); // bool(false)

« previous php.notes (#151255) next »