Re: SimpleXML addChild() namespace problem

From: Date: Fri, 18 Jan 2008 17:04:35 +0000
Subject: Re: SimpleXML addChild() namespace problem
Groups: php.general 
Request: Send a blank email to php-general+get-267570@lists.php.net to get a copy of this message
>based upon information from bug #43221, if you define the namespace >beforehand >it will work. > ><?php >$xml = new SimpleXMLElement('<root >xmlns:itunes="http://apple.com"/>'); >$n = $xml->addChild("subtitle", "Musical Mockery", "^Bh >å±C5Øù’http://apple.com"); >print_r($xml->asXml()); >?> > >produces: ><?xml version="1.0"?> ><root >xmlns:itunes="http://apple.com"><itunes:subtitle>Musical >Mockery</itunes:subtitle></root> > >-nathan Actually, it doesn't work. I did exactly this, and still got: <?xml version="1.0" encoding="UTF-8"?> <rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> <channel> <!-- snipping, some elements omitted ... --> <item> <title>My Title</title> <link>My Link</link> <description>My Description</description> <itunes:author xmlns:itunes="itunes">My Author</itunes:author> <itunes:subtitle xmlns:itunes="itunes">My Subtitle</itunes:subtitle> <!-- snipping, more elements omitted ... --> </item> </channel> </rss> -Carole

« previous php.general (#267570) next »