To add new brand xml namespace use:
<?php
$element->setAttributeNS(
'http://www.w3.org/2000/xmlns/', // xmlns namespace URI
'xmlns:mynamespace',
'example.com/mynamespace'
);
?>
'http://www.w3.org/2000/xmlns/' URI is important
to be able to add new namespaces !!!
Later you can use your namespace like:
<?php
$element->setAttributeNS(
'example.com/mynamespace',
'mynamespace:something',
'value'
);
?>
DOMElement::setAttributeNS
(PHP 5)
DOMElement::setAttributeNS — Añade un nuevo atributo
Descripción
void DOMElement::setAttributeNS
( string
$namespaceURI
, string $qualifiedName
, string $value
)
Establece un atributo con el espacio de nombres namespaceURI y
el nombre name al valor dado. Si el atributo
no existe, se creará.
Parámetros
-
namespaceURI -
La URI del espacio de nombres.
-
qualifiedName -
El nombre cualificado del atributo, como prefijo:nombre_etiqueta.
-
value -
El valor del atributo.
Valores devueltos
No devuelve ningún valor.
Errores/Excepciones
-
DOM_NO_MODIFICATION_ALLOWED_ERR -
Lanzado si el nodo es de sólo lectura.
-
DOM_NAMESPACE_ERR -
Lanzado si
qualifiedNamees un nombre cualificado malformado, o siqualifiedNametienen un prefijo ynamespaceURIesNULL.
Ver también
- DOMElement::hasAttributeNS() - Comprueba si un atributo existe
- DOMElement::getAttributeNS() - Devuelve el valor de un atributo
- DOMElement::removeAttributeNS() - Elimina un atributo
catalinenache78 at gmail dot com ¶
2 years ago
