Well, as I said, I rewrote my code to take care of the namespaces in the DOM extension. This works as follows:
class Foo { const XMLNS = 'http://www.w3.org/2000/xmlns/'; public static final function registerNS(DOMElement $element, $namespaceUri, $prefix=null) { Preconditions::checkNotEmpty($namespaceUri); $name = "xmlns"; if (!empty($prefix)) { $name .= ":$prefix"; } $element->setAttributeNS(self::XMLNS, $name, $namespaceUri); } }
Now, every time (every time here, to ease the situation). I add an element as a child of another element, I call this method and basically provide documentElement as the first parameter to add namespaces to the root element:
DOMDocument $doc = [...]; DOMElement $element = [...]; DOMElement $newChild = [...]; Foo::registerNS($doc->documentElement, $newChild->namespaceURI, $newChild->prefix); $element->appendChild($newChild);
source share