CakeFest 2024: The Official CakePHP Conference

DOMElement::removeAttributeNS

(PHP 5, PHP 7, PHP 8)

DOMElement::removeAttributeNS属性を削除する

説明

public DOMElement::removeAttributeNS(?string $namespace, string $localName): void

名前空間 namespace にある localName という名前の属性を 要素から削除します。

パラメータ

namespace

名前空間 URI。

localName

ローカル名。

戻り値

値を返しません。

エラー / 例外

DOM_NO_MODIFICATION_ALLOWED_ERR

ノードが読み込み専用の場合に発生します。

参考

add a note

User Contributed Notes 1 note

up
3
primaryspace at hotmail dot com
18 years ago
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());

?>
To Top