note 89258 added to function.simplexml-element-xpath

From: Date: Sat, 28 Feb 2009 16:01:32 +0000
Subject: note 89258 added to function.simplexml-element-xpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-151248@lists.php.net to get a copy of this message
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) ---- Server IP: 130.206.1.5 Probable Submitter: 84.123.119.214 ---- Manual Page -- http://www.php.net/manual/en/function.simplexml-element-xpath.php Edit -- https://master.php.net/note/edit/89258 Del: integrated -- https://master.php.net/note/delete/89258/integrated Del: useless -- https://master.php.net/note/delete/89258/useless Del: bad code -- https://master.php.net/note/delete/89258/bad+code Del: spam -- https://master.php.net/note/delete/89258/spam Del: non-english -- https://master.php.net/note/delete/89258/non-english Del: in docs -- https://master.php.net/note/delete/89258/in+docs Del: other reasons-- https://master.php.net/note/delete/89258 Reject -- https://master.php.net/note/reject/89258 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151248) next »