I am creating an Atom feed, when I tried below to add xmlns:i as an attribute -
$node->addAttribute(\"xmlns:i\",\"http://www.w3.org/2001/XML
I found this looking for the same thing, and none of the answers really worked for me. So, I tried a different route. If SimpleXML isn't managing namespace correctly, use DOM instead.
So, something like this should work:
$s = new simplexmlelement(' ');
$d = dom_import_simplexml($s);
$d->setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:i", "http://www.w3.org/2001/XMLSchema-instance");
$s->addChild("bar", "bazy", "http://www.w3.org/2001/XMLSchema-instance");
$f = $s->addChild("foo", "quux");
$f->addAttribute("i:corge", "grault", "http://www.w3.org/2001/XMLSchema-instance");
That will result in this:
bazy
quux