note 89815 added to function.simplexml-element-xpath
| From: | pvenakis at efrontlearning dot net | Date: | Tue, 24 Mar 2009 15:04:32 +0000 |
| Subject: | note 89815 added to function.simplexml-element-xpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152389@lists.php.net to get a copy of this message | ||
Both notes below are very useful, thank you both!
But it's not apparent what to do to access a specific value. Here's an slightly different
example:
<?php
$xml_doc = <<<XML
<?xml version='1.0'?>
<!-- without namespace: -->
<!-- <document> -->
<!-- with default namespace: -->
<manifest xmlns="uri:some_namespace">
<metadata>
<schemaversion>SCORM 1.2</schemaversion>
</metadata>
</manifest>
XML;
$xml = simplexml_load_string($xml_doc);
$namespaces = $xml->getNamespaces(true);
// register a prefix for that default namespace:
$xml->registerXPathNamespace("default", $namespaces[""]);
// and use that prefix in all of your xpath expressions:
$xpath_to_schemaversion = "//default:manifest/default:metadata/default:schemaversion";
var_dump($xml->xpath($xpath_to_schemaversion));
----
Server IP: 85.196.44.41
Probable Submitter: 79.103.201.146
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-xpath.php
Edit -- https://master.php.net/note/edit/89815
Del: integrated -- https://master.php.net/note/delete/89815/integrated
Del: useless -- https://master.php.net/note/delete/89815/useless
Del: bad code -- https://master.php.net/note/delete/89815/bad+code
Del: spam -- https://master.php.net/note/delete/89815/spam
Del: non-english -- https://master.php.net/note/delete/89815/non-english
Del: in docs -- https://master.php.net/note/delete/89815/in+docs
Del: other reasons-- https://master.php.net/note/delete/89815
Reject -- https://master.php.net/note/reject/89815
Search -- https://master.php.net/manage/user-notes.php