note 103392 added to simplexmlelement.addchild
| From: | felipenmoura at gmail dot com | Date: | Tue, 12 Apr 2011 01:06:18 +0000 |
| Subject: | note 103392 added to simplexmlelement.addchild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178714@lists.php.net to get a copy of this message | ||
This method returns a reference to the specific SimpleXMLElement.
If you use:
<?php
$xml= new SimpleXMLElement('<root></root>');
$xml->father['name']= 'Fathers name'; // creates automatically a father tag
with attribute name
$son= $xml->father->addChild('son'); // uses the first father tag
$son['name']= 'first son';
$otherSon= $xml->father->addChild('son'); // uses the first father tag but now, in
a second son tag
$otherSon['name']= 'second son';
echo htmlentities($xml->asXML());
?>
The result will be
<root>
<father>
<son name='first son' />
<son name='second son' />
</father>
</root>
So, once you change something to the just added child, you are actually accessing the element inside
the SimpleXMLElement as a reference.
----
Server IP: 187.16.23.128
Probable Submitter: 189.27.186.165
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.addchild.php
Edit -- https://master.php.net/note/edit/103392
Del: integrated -- https://master.php.net/note/delete/103392/integrated
Del: useless -- https://master.php.net/note/delete/103392/useless
Del: bad code -- https://master.php.net/note/delete/103392/bad+code
Del: spam -- https://master.php.net/note/delete/103392/spam
Del: non-english -- https://master.php.net/note/delete/103392/non-english
Del: in docs -- https://master.php.net/note/delete/103392/in+docs
Del: other reasons-- https://master.php.net/note/delete/103392
Reject -- https://master.php.net/note/reject/103392
Search -- https://master.php.net/manage/user-notes.php