note 84239 added to function.simplexml-element-xpath

From: Date: Fri, 04 Jul 2008 15:35:54 +0000
Subject: note 84239 added to function.simplexml-element-xpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-141173@lists.php.net to get a copy of this message
It seems that PHP 5.2.6 also has some problems with default namespaces and xpath. If you are working with complex documents (in my case SCORM manifest XML files) and your xpath is not working, try registering the default namespace. The XML is too long to add as an example but the snippet of code that was failing was: <?php ... $xpath = "//resource[@identifier='$id']"; $resourceArr = $this->xmlObj->xpath($xpath); .. ?> This despite the resource tag being in the default namespace. Registering the namespace like this then solved the problem: <?php ... $this->xmlObj->registerXPathNamespace('default', 'http://www.imsglobal.org/xsd/imscp_v1p1'); $xpath = "//default:resource[@identifier='$id']"; $resourceArr = $this->xmlObj->xpath($xpath); ... ?> ---- Server IP: 64.71.164.2 Probable Submitter: 87.194.4.226 ---- Manual Page -- http://www.php.net/manual/en/function.simplexml-element-xpath.php Edit -- https://master.php.net/note/edit/84239 Del: integrated -- https://master.php.net/note/delete/84239/integrated Del: useless -- https://master.php.net/note/delete/84239/useless Del: bad code -- https://master.php.net/note/delete/84239/bad+code Del: spam -- https://master.php.net/note/delete/84239/spam Del: non-english -- https://master.php.net/note/delete/84239/non-english Del: in docs -- https://master.php.net/note/delete/84239/in+docs Del: other reasons-- https://master.php.net/note/delete/84239 Reject -- https://master.php.net/note/reject/84239 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#141173) next »