note 91232 modified in function.simplexml-element-addChild by danbrown

From: Date: Wed, 16 Sep 2009 16:37:24 +0000
Subject: note 91232 modified in function.simplexml-element-addChild by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160732@lists.php.net to get a copy of this message
If you want to add a child element that is prefixed by a namespace like this one: <content:encoded> then this is what you need to do: <?php $parent->addChild('content:encoded', 'some actual content here', ''http://purl.org/rss/1.0/modules/content/''); ?> Make sure you declared the namespace at some parent element, preferrably at root: <root xmlns:content="http://purl.org/rss/1.0/modules/content/"> This will create a child element that will look like this when object dumpted as xml string: <content:encoded> If you are adding child this way: <?php $parent->addChild('encoded', 'some actual content here', ''content''); ?> then your child element will look like this: <encoded xmlns="content"> which is also a valid xml tag and basically has the same exact value as <content:encoded> but just looks different. --was-- If you want to add a child element that is prefixed by a namespace like this one: <content:encoded> then this is what you need to do: $parent->addChild('content:encoded', 'some actual content here', ''http://purl.org/rss/1.0/modules/content/''); Make sure you declared the namespace at some parent element, preferrably at root: <root xmlns:content="http://purl.org/rss/1.0/modules/content/"> This will create a child element that will look like this when object dumpted as xml string: <content:encoded> If you are adding child this way: $parent->addChild('encoded', 'some actual content here', ''content''); then your child element will look like this: <encoded xmlns="content"> which is also a valid xml tag and basically has the same exact value as <content:encoded> but just looks different. http://php.net/manual/en/function.simplexml-element-addChild.php

« previous php.notes (#160732) next »