I'm looking DOMDocument::createElementNS documentation at: http://php.net/manual/en/domdocument.createelementns.php
it says that second variable "qualifiedName" has to be in defined as prefix:tagname but I found out that in some cases the prefix is added automatically (without me entering it in the code). I have made an examle:
<?php
//Namespaces url
$NS_xx = 'http://xxx';
$NS_yy = 'http://yyy';
$domxml = new DomDocument('1.0', 'UTF-8');
$Country = $domxml->appendChild ($domxml->createElementNS($NS_xx, 'xx:Country')); // Manually entered prefix
$Country->setAttributeNS($NS_xx, 'id', '1'); // Automatically added prefix in result
$State = $Country->appendChild ($domxml->createElementNS($NS_xx,'State')); // Automatically added prefix in result
$Region = $State->appendChild ($domxml->createElementNS($NS_yy, 'yy:Region')); // Manually entered prefix
$Region->setAttributeNS($NS_xx, 'id', '5'); // Automatically added prefix in result
$Town = $Region->appendChild ($domxml->createElement('Town'));
$Town->appendChild ($domxml->createElementNS($NS_yy, 'F', 'New York')); // Automatically added prefix in result
$Town->setAttributeNS($NS_xx, 'zip', '10001'); // Automatically added prefix in result
Header('Content-type: text/xml');
$domxml->formatOutput = true;
echo $domxml->saveXML();
?>
It gives back:
<?xml version="1.0" encoding="UTF-8"?>
<xx:Country xmlns:xx="http://xxx" xx:id="1">
<xx:State>
<yy:Region xmlns:yy="http://yyy" xx:id="5">
<Town xx:zip="10001">
<yy:F>New York</yy:F>
</Town>
</yy:Region>
</xx:State>
</xx:Country>
It seems to me that prefix will be added automatically if it has been previously added in any of the parent elements. Is there any reason to add that prefix anyway every time in code? If I add those prefixes manually in my code as the documentation says, the result xml will be the same...