DOM - 文档类型对象属性 - 实体



entities 属性返回一个命名节点映射对象,该对象包含 DTD 中声明的通用实体(包括外部实体和内部实体)。

语法

以下为 entities 属性用法的语法。

documentObj.doctype.entities

示例

address_internal_dtd.xml 的内容如下:

<?xml version = "1.0" encoding = "UTF-8" standalone = "no"?>
<!DOCTYPE address [
   <!ELEMENT address    (name,company,phone)>
   <!ELEMENT name    (#PCDATA)>
   <!ELEMENT company   (#PCDATA)>
   <!ELEMENT phone (#PCDATA)>
]>

<address>
   <name>Tanmay Patil</name >
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</address>

以下示例演示了 entities 属性的用法:

<!DOCTYPE html>
   <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("/dom/address_internal_dtd.xml");

         x = xmlDoc.doctype.entities;

         document.write("Nodename is: " + xmlDoc.nodeName);
         document.write("<br>");
         document.write(" nodetype is: " + xmlDoc.nodeType + "<br>");

         y = xmlDoc.documentElement;
         document.write("Nodename is: " + y.nodeName);
         document.write("<br>");
         document.write(" nodetype is: " + y.nodeType + "<br>");
      </script>
   </body>
</html>

执行

将此文件在服务器路径上存储为 documenttype_entities.html(此文件和 address_internal_dtd.xml 应在服务器中的同一个路径下)。我们将获得以下输出:

Nodename is: #document
nodetype is: 9
Nodename is: address
nodetype is: 1
dom_documenttype_object.htm
广告