Writing an attribute in 5.2.4 for a newb

I am a newb with PHP, I admit.

I am writing an XML file with PHP from user input forms. I have it writing the file perfectly. What I want to do now is add an attribute to my nodes. How do I write that>

I have tried :


 $module = $modules->appendChild($dom->addAttribute('type', 'reprints'));

and it doesn’t work.

Everything else is great but this and I can’t find anything that works online. Any help would be greatly appreciated.

thank you.