SimpleXML addChild() namespace problem
| From: | Carole E. Mah | Date: | Tue, 15 Jan 2008 03:22:58 +0000 |
| Subject: | SimpleXML addChild() namespace problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-267269@lists.php.net to get a copy of this message | ||
This is problematic code, even though it works, because it
auto-generates an unnecessary xmlns: attribute:
$item->addChild('itunes:subtitle', $mySubTitle,"itunes");
It generates the following XML:
<itunes:subtitle xmlns:itunes="itunes">Musical Mockery</itunes:subtitle>
When really all we want is this:
<itunes:subtitle>Musical Mockery</itunes:subtitle>
Furthermore, dumping it into a DomDocument and attempting to use
removeAttributeNS() to remove the spurious attribute removes the
entire kit and kaboodle, leaving only:
<subtitle>Musical Mockery</subtitle>
How can one get the desired result, short of using a regexp? (I have
done this, and it works, but is a silly hack because it doesn't use
XML parsing to address an XML problem).
Thanks,
Carole