DOM Entity物件publicId屬性

2019-10-16 23:19:11

DOM Entity物件publicId屬性返回關聯實體的公共識別符號或返回null

語法

以下是publicId屬性的使用語法。

document.doctype.publicId;

範例

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

<?xml version = "1.0" encoding = "UTF-8" standalone = "no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<address id = "firstelement">
   <name>Tianya Su</name >
   <company>Yiibai Yiibai</company>
   <phone>(0980) 90124567</phone>
</address>

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

<!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");
         document.write("<b>publicid :</b> "+xmlDoc.doctype.publicId);
      </script>
   </body>
</html>

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