Goetas\Twital\Helper\DOMHelper::copyElementInNs PHP Method

copyElementInNs() public static method

public static copyElementInNs ( DOMElement $oldElement, string $newNamespace ) : mixed
$oldElement DOMElement
$newNamespace string
return mixed
    public static function copyElementInNs($oldElement, $newNamespace)
    {
        $element = $oldElement->ownerDocument->createElementNS($newNamespace, $oldElement->nodeName);
        // copy attributes
        foreach (iterator_to_array($oldElement->attributes) as $attr) {
            $oldElement->removeAttributeNode($attr);
            if ($attr->namespaceURI) {
                $element->setAttributeNodeNS($attr);
            } else {
                $element->setAttributeNode($attr);
            }
        }
        // copy children
        while ($child = $oldElement->firstChild) {
            $oldElement->removeChild($child);
            $element->appendChild($child);
        }
        $oldElement->parentNode->replaceChild($element, $oldElement);
        return $element;
    }