This method can be used to remove a namespace declaration from an element, even though the declaration is not considered an attribute by the DOM. The prefix will be removed from any element or attribute using it.
<?php
$dom = DOMDocument::loadXML('<foo:root xmlns:foo="http:bar"/>');
$element = $dom->childNodes->item(0);
// prints '0':
echo (int) $element->hasAttributeNS('http:bar', 'foo');
$element->removeAttributeNS('http:bar', 'foo');
/* prints '<?xml version="1.0"?> <root/>': */
print htmlentities($dom->saveXML());
?>
DOMElement::removeAttributeNS
(PHP 5)
DOMElement::removeAttributeNS — 属性を削除する
説明
bool DOMElement::removeAttributeNS
( string $namespaceURI
, string $localName
)
名前空間 namespaceURI にある localName という名前の属性を 要素から削除します。
パラメータ
- namespaceURI
-
名前空間 URI。
- localName
-
ローカル名。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
エラー / 例外
- DOM_NO_MODIFICATION_ALLOWED_ERR
-
ノードが読み込み専用の場合に発生します。
参考
- DOMElement::hasAttributeNS - 属性が存在するかどうかを調べる
- DOMElement::getAttributeNS - 属性の値を返す
- DOMElement::setAttributeNS - 新しい属性を追加する
DOMElement::removeAttributeNS
primaryspace at hotmail dot com
11-Aug-2005 04:56
11-Aug-2005 04:56
