src/Nodes/NodeUtility.php
public static function setNodeTag($node, $value, $importAttributes = true)
    {
        $new = new DOMDocument('1.0', 'utf-8');
        $new->appendChild($new->createElement($value));

        $children = $node->childNodes;
        /** @var $children \DOMNodeList $i */
        for ($i = 0; $i < $children->length; $i++) {
            $import = $new->importNode($children->item($i), true);
            $new->firstChild->appendChild($import);
        }

        if ($importAttributes) {
            // Import attributes from the original node.
            foreach ($node->attributes as $attribute) {
                $new->firstChild->setAttribute($attribute->nodeName, $attribute->nodeValue);
            }
        }

        // The import must be done on the firstChild of $new, since $new is a DOMDocument and not a DOMElement.
        $import = $node->ownerDocument->importNode($new->firstChild, true);
        $node->parentNode->replaceChild($import, $node);

        return $import;
    }
public static function setNodeTag($node, $value, $importAttributes = true)
    {
        $new = new DOMDocument('1.0', 'utf-8');
        $new->appendChild($new->createElement($value));

        $children = $node->childNodes;
        /** @var $children \DOMNodeList $i */
        for ($i = 0; $i < $children->length; $i++) {
            $import = $new->importNode($children->item($i), true);
            $new->firstChild->appendChild($import);
        }

        if ($importAttributes) {
            // Import attributes from the original node.
            foreach ($node->attributes as $attribute) {
                $new->firstChild->setAttribute($attribute->nodeName, $attribute->nodeValue);
            }
        }

        // The import must be done on the firstChild of $new, since $new is a DOMDocument and not a DOMElement.
        $import = $node->ownerDocument->importNode($new->firstChild, true);
        $node->parentNode->replaceChild($import, $node);

        return $import;
    }
public static function setNodeTag ( $ node , $ value , $ importAttributes = true ) { $ new = new DOMDocument ( '1.0' , 'utf-8' ) ; $ new -> appendChild ( $ new -> createElement ( $ value ) ) ; $ children = $ node -> childNodes ; /** @var $children \DOMNodeList $i */ for ( $ i = 0 ; $ i < $ children -> length ; $ i ++ ) { $ import = $ new -> importNode ( $ children -> item ( $ i ) , true ) ; $ new -> firstChild -> appendChild ( $ import ) ; } if ( $ importAttributes ) { // Import attributes from the original node. foreach ( $ node -> attributes as $ attribute ) { $ new -> firstChild -> setAttribute ( $ attribute -> nodeName , $ attribute -> nodeValue ) ; } } // The import must be done on the firstChild of $new, since $new is a DOMDocument and not a DOMElement. $ import = $ node -> ownerDocument -> importNode ( $ new -> firstChild , true ) ; $ node -> parentNode -> replaceChild ( $ import , $ node ) ; return $ import ; }
Changes the node tag name. Since tagName on DOMElement is a read only value, this must be done creating a new
element with the new tag name and importing it to the main DOMDocument.

@param DOMNode $node
@param string $value
@param bool $importAttributes

@return DOMNode
Changes the node tag name . Since tagName on DOMElement is a read only value this must be done creating a new element with the new tag name and importing it to the main DOMDocument .