note 87011 deleted from simplexml.examples by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 08:03:17 +0000 |
| Subject: | note 87011 deleted from simplexml.examples by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196771@lists.php.net to get a copy of this message | ||
Note Submitter: Edward Rudd
----
If you need to updated the content of a node selected via Xpath use [0]. Example.
<?php
$x = new SimpleXMLElement(<<<EOXML
<root>
<node>Some Text</node>
</root>
EOXML
);
$nodes = $x->xpath('/root/node');
// This does not work
// $nodes[0] = "My New Text";
$nodes[0][0] = "My New Text";
echo $x->asXML();
?>
Note that this for some reason doesn't work.
<?php
$node = $nodes[0];
$nodes[0] = "My New Text";
?>
It throw an exception "Object ($node) don't support array access operators"