DOM DocumentType对象name属性

DOM DocumentType对象name属性返回紧跟在关键字!DOCTYPE旁边写入的DTD的名称。

语法
以下是name属性的使用语法。

documentObj.doctype.name

示例

文件: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>Tianya Su</name >
   <company>zaixian zaixian</company>
   <phone>(011) 123-456789</phone>
</address>

以下示例演示了name属性的用法 -

<!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("/address_internal_dtd.xml");
         document.write("关键字doctype旁边的名称是:"+ xmlDoc.doctype.name);
      </script>
   </body>
</html>

执行上面示例代码,得到以下结果 -


上一篇: DOM DocumentType对象 下一篇: ProcessingInstruction对象