note 112342 deleted from domelement.setattributens by danbrown
| From: | danbrown@php.net | Date: | Wed, 05 Jun 2013 17:37:08 +0000 |
| Subject: | note 112342 deleted from domelement.setattributens by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195051@lists.php.net to get a copy of this message | ||
Note Submitter: hrvoj3e
----
http://stackoverflow.com/questions/2236931/php-dom-xml-create-multiple-namespace-attributes/16911033#16911033
// create DOM document
$xml = new DomDocument('1.0', 'UTF-8');
// create root element
$el = $xml->createElementNS('xttp://namespaceA/url/here/', 'rootelement');
// to be able to add new namespaces we must first add namespace 'xsi'
// third parameter is important (use your main namespace with .xsd)
$root->setAttributeNS(
'xttp://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation',
'xttp://namespaceA/url/here/ xttp://namespaceA/xsdfile/here.xsd');
// add new namespace
$el->setAttributeNS(
'http://www.w3.org/2000/xmlns/',
'xmlns:namespaceB',
'http://namespaceB/url/here/');
// add root element to DOM
$xml->appendChild($el);