note 84239 deleted from function.simplexml-element-xpath by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Sep 2009 15:50:58 +0000 |
| Subject: | note 84239 deleted from function.simplexml-element-xpath by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160677@lists.php.net to get a copy of this message | ||
Note Submitter: Matt
----
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);
...
?>