Search code examples
phpxmlrsssimplexml

How to add an atom:link element to an RSS XML in PHP


I'm creating the XML for my RSS feed programatically in PHP.

It's all good except for one thing - I can't create the <atom:link> element correctly.

With any other element, this works:

$channel->addChild('title', "My Blog");

But when I try this...

$channel->addChild('atom:link');

...it creates a <link> element and not the expected <atom:link>. I've tried adding the atom part as a namespace but that just creates <link xlmns='atom'> instead.

How can I do this?


Solution

  • You can pass a third parameter as the namespace where atom:link is available.

    $root->addChild('atom:link','','http://www.w3.org/2005/Atom');
    

    Addchild Docs