Q:

Attribute not creating using DomDocument in PHP

I am stuck with DomDocument
This thing is working fine, no doubt -
$resource1->appendChild($dom->createAttribute('type'))
          ->appendChild($dom->createTextnode("webcontent"));

It is adding type="webcontent" to resource node
However when I am using this code its not adding it to it -
$resource1->appendChild($dom->createAttribute('adlcp:scormType'))
          ->appendChild($dom->createTextnode("sco"));

Expected to generate - adlcp:scormType="sco" <-- Not Working
However If I am creating 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <-- Working
Code - 
$manifestNode->appendChild($dom->createAttribute('xmlns:xsi'))
             ->appendChild($dom->createTextNode("http://www.w3.org/2001/XMLSchema-instance"));

Let me know what I am doing wrong and how do I make it working
EDIT
Error -

XML Parsing Error: prefix not bound to a namespace

Googled same with the keyword - xml parsing error prefix not bound to a namespace php but not much help. 

A:

To set an attribute on a node:
$resource1->setAttribute('type', 'webcontent');

To set a namespaced attribute on a node (assuming this is the namespace represented by the "adlcp" prefix):
$resource1->setAttributeNS('http://www.adlnet.org/xsd/adlcp_rootv1p2', 'adlcp:scormType', 'sco');

