DOM - DocumentType 对象属性 - entities
属性 entities 返回一个 NamedNodeMap 对象,其中包含 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