createElementNS and createAttributeNS

Creating an element or attribute is somewhat different if namespaces are to be taken into consideration. You must specify a namespace URI and a qualified name.

A namespace URI is a unique identifier for the namespace, written in the form of an http address (although not required to be a live url!). In the case of the Dublin Core, the namespace URI is always http://purl.org/dc/elements/1.1/.

A qualified name is a combination of the namespace prefix (if one exists), a semi colon, and the name of the tag, which is called the local name. The qualified name of the Dublin Core creator tag would be dc:creator.

To create a Dublin Core creator element, one would use the createElementNS method:

$myElement =& $xmldoc->createElementNS('http://purl.org/dc/elements/1.1/', 'dc:creator');

Attributes with namespaces are created similarly:

$myAttribute =& $xmldoc->createAttributeNS('http://www.engageinteractive.com/tests', 'ei:score');

Note that if you have invoked an instance of DOMIT! with namespace awareness, you should not use the DOM Level 1 methods createElement and createAttribute.


Documentation generated by ClassyDoc, using the DOMIT! and SAXY parsers.
Please visit Engage Interactive to download free copies.