DOM DocumentType物件notations屬性

2019-10-16 23:19:26

包含DTD中宣告的符號的屬性表示法。

範例

檔案:notation.xml 的內容如下 -

<?xml version = "1.0"?>
<!DOCTYPE address [
   <!ELEMENT address (#PCDATA)>
   <!NOTATION name PUBLIC "Yiibai">
   <!ATTLIST address category NOTATION (name) #REQUIRED>
]>

<address name = "Yiibai">Hello Yiibai!</address>

以下範例演示了符號屬性的用法 -

<!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("/notation.xml");
         var notations = xmlDoc.doctype.notations;
         document.write("notations: "+notations);
         document.write("Item "+notations.getNamedItem('Yiibai'));
      </script>
   </body>
</html>

瀏覽器不太支援此集合,但沒有其他方法可以檢索此資料。

執行上面範例程式碼,得到以下結果 -