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>Yiibai Yiibai</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>
執行上面範例程式碼,得到以下結果 -