note 56571 modified in ref.simplexml by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 01:26:11 +0000 |
| Subject: | note 56571 modified in ref.simplexml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155536@lists.php.net to get a copy of this message | ||
While you can't add new elements to a SimpleXML object you can however add new attributes
<?php
$string = '<doc
channel="chat"><test1>Hello</test1></doc>';
$xml = simplexml_load_string($string);
$xml->test1['sub'] = 'No';
echo $xml->asXML();
?>
Will return output
<doc channel="chat"><test1 sub="No">Hello</test1></doc>
--was--
While you can't add new elements to a SimpleXML object you can however add new attributes
<?php
$string = '<doc
channel="chat"><test1>Hello</test1></doc>';
$xml = simplexml_load_string($string);
$xml->test1['sub'] = 'No';
echo $xml->asXML();
?>
Will return output
<doc channel="chat"><test1 sub="No">Hello</test1></doc>
http://php.net/manual/en/ref.simplexml.php