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 — اضافه کردن ویژگی جدید
Description
void DOMElement::setAttributeNS
( string $namespaceURI
, string $qualifiedName
, string $value
)
تعیین ویژگی با فضای نام namespaceURI و نام name به مقدار داده شده. اگر ویژگی وجود نداشته باشد ساخته میشود.
Parameters
- namespaceURI
-
فضای نام URI.
- qualifiedName
-
نام مناسب ویژگی به عنوان prefix:tagname.
- value
-
مقدار ویژگی.
Return Values
No value is returned.
Errors/Exceptions
- DOM_NO_MODIFICATION_ALLOWED_ERR
-
ایجاد اگر گره فقط خواندنی باشد.
- DOM_NAMESPACE_ERR
-
ایجاد اگر qualifiedName نام ناقص باشد یا اگر qualifiedName پیشوند داشته باشد و namespaceURI NULL باشد.
See Also
- DOMElement::hasAttributeNS() - بررسی وجود ویژگی
- DOMElement::getAttributeNS() - بازگرداندن مقدار ویژگی
- DOMElement::removeAttributeNS() - حذف ویژگی
catalinenache78 at gmail dot com ¶
2 years ago
