I am trying to use PHP to create an XML document that will be used for an RSS feed. I've got it working for the most part, but I am getting a error on line 2 at column 29: redefinition of the xmlns prefix is forbidden while attempting to add an attribute with a namespace to my document.
I've tried the accepted answer here:
Add rss xmlns namespace definition to a php simplexml document? but that changes the first line to <rss... instead of <xml...
Here is the code that I am working with:
<?php
$xml = new SimpleXMLElement('<xml vesion="1.0" />');
$rss = $xml->addChild('rss');
$rss->addAttribute('version','2.0');
$rss->addAttribute("xml:base",'http://intranet/bapm/rss-avd','xml');
$rss->addAttribute('xmlns:dc',"http://purl.org/dc/elements/1.1/",'xmlns');
....
the line that adds the xml:base attribute works fine, but when I add the line that adds the xmlns:dc attribute I get the error. If I don't add the 'xmlns' as the third argument, I get no errors, but the rendered attribute omits the namespace?
XMLare reserved in XML. don't use them. (and you likely do not want to create such a root element here) - So please trouble-shoot a bit before posting a question.$rss->addAttribute('xmlns:dc', ...can never work because that is an invalid attribute. Like with the root element, it is very likely that you want to do something different here, for example adding a Namespace Declaration which might look in your eyes like an attribute - but it ain't one (yes keep that in mind, it's not an attribute, it looks like one, but it's not an attribute).