note 110740 added to function.simplexml-load-file
| From: | uramihsayibok | Date: | Thu, 29 Nov 2012 22:16:05 +0000 |
| Subject: | note 110740 added to function.simplexml-load-file | ||
| Groups: | php.notes php.notes | ||
| Request: | Send a blank email to php-notes+get-192207@lists.php.net to get a copy of this message | ||
kannan's note about how colons seem to be special characters in element names, and using
hyphens instead (renaming <node:number> to <node-number>), is because of XML namespaces.
<?php
$xml = simplexml_load_string("
<root xmlns:node='uri:foo'>
<node:number>1538-7445</node:number>
</root>");
// you might think $xml->node:number would work. no, that's not valid PHP syntax
// ah right, of course. so how about
echo $xml->{"node:number"}; // nope
// (the syntactically-valid way of writing the same thing)
// will not work because there is no element named "node:number"
// I'll say that again: there is no element named "node:number"
// what you want is the element named "number" *in the node namespace*
echo $xml->number; // nope
// that looks for "number" in the default (empty) namespace
// use SimpleXMLElement::children() to switch namespaces
echo $xml->children("node", true)->number; // works by the namespace name
echo $xml->children("uri:foo")->number; // works by the namespace URI
?>
----
Server IP: 69.147.83.199
Probable Submitter: 173.160.229.61
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-load-file.php
Edit -- https://master.php.net/note/edit/110740
Del: integrated -- https://master.php.net/note/delete/110740/integrated
Del: useless -- https://master.php.net/note/delete/110740/useless
Del: bad code -- https://master.php.net/note/delete/110740/bad+code
Del: spam -- https://master.php.net/note/delete/110740/spam
Del: non-english -- https://master.php.net/note/delete/110740/non-english
Del: in docs -- https://master.php.net/note/delete/110740/in+docs
Del: other reasons-- https://master.php.net/note/delete/110740
Reject -- https://master.php.net/note/reject/110740
Search -- https://master.php.net/manage/user-notes.php