DOM DocumentType物件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>Tianya Su</name >
<company>Yiibai Yiibai</company>
<phone>(011) 123-456789</phone>
</address>
以下範例演示了entities
屬性的用法 -
<!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");
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>
執行上面範例程式碼,得到以下結果 -