note 89010 deleted from function.simplexml-element-addChild by danbrown
| From: | danbrown@php.net | Date: | Wed, 18 Feb 2009 14:34:57 +0000 |
| Subject: | note 89010 deleted from function.simplexml-element-addChild by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150797@lists.php.net to get a copy of this message | ||
Note Submitter: brettz9 aaat yah dot company
----
Chicken dot ofeathers comment was a little off. The incorrect example of:
<?php
$xml = new SimpleXMLElement('<root xmlns:itunes="http://example.com"/>');
$n = $xml->addChild("subtitle", "My Subtitle", "itunes");
?>
leads to:
<subtitle xmlns="itunes">My Subtitle</subtitle>
not <itunes:subtitle xmlns:itunes="itunes">My Subtitle</itunes:subtitle>
This is because "itunes" is already in the "http://example.com" namespace, and we're specifying a
new namespace of value "itunes" (it would be prefixed with "itunes:" if
xmlns:itunes were set to "itunes" on the parent, however).
Note that you cannot control the prefix from this function (as with addAttribute)--you must
apparently rely on an existing namespace, as per chicken dot ofeather's comments.