Documentación offline PHP master

DOMElement::setAttributeNodeNS

master Ver versión oficial en línea Licencia CC-BY-3.0Descargado el 2026-08-02

En esta página

DOMElement::setAttributeNodeNS

Añade un nuevo atributo al elemento

Descripción#

php public DOMElement::setAttributeNodeNS(DOMAttr $attr): DOMAttrphp

Añade un nuevo atributo attr al elemento, teniendo en cuenta el espacio de nombres (namespace): Si ya existe un atributo con el mismo nombre en el elemento, este atributo es reemplazado por attr.

Parámetros#

attr
El nombre del atributo.

Valores devueltos#

Devuelve el antiguo atributo si ha sido reemplazado o null si no había un atributo anterior. Si se produce un error DOM_WRONG_DOCUMENT_ERR y strictErrorChecking es false, entonces se devuelve false.

Errores/Excepciones#

Puede lanzar una DOMException con los siguientes códigos de error:

DOM_WRONG_DOCUMENT_ERR
Se lanza si attr pertenece a un documento diferente al del elemento.

Véase también#

DOMElement::hasAttributeNS, DOMElement::getAttributeNodeNS, DOMElement::removeAttributeNode