XML DOM hasAttributeNS() Method
Definition and Usage
If the attribute is composed of a specified namespace and name, the hasAttributeNS() method returns true, otherwise it returns false.
Grammar:
hasAttributeNS(ns,name)
パラメータ | 説明 |
---|---|
ns | 必須。検索する属性の名前空間を指定します。 |
name | 必須。検索する属性の名前を指定します。 |
説明
このメソッドは hasAttribute() メソッド同様に、ただし、確認する属性は名前空間と名前で指定されます。名前空間を持つ XML ドキュメントのみがメソッドを使用します。
インスタンス
すべての例では、XML ファイルを使用します books_ns.xml、および JavaScript ファンクション loadXMLDoc()。
以下のコードスニペットは、"books_ns.xml" 内の最初の <title> タグが指定された名前空間と名前を持つ属性を持つかどうかを確認します:
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
ns="http://www.codew3c.com/children/";
document.write(x.hasAttributeNS(ns,"lang")
);
上記のコードの出力:
true