Dom-documenttype-entities
提供:Dev Guides
DOM-DocumentTypeオブジェクト属性-エンティティ
属性_entities_は、DTDで宣言された外部および内部の一般的なエンティティを含むNamedNodeMapオブジェクトを返します。
構文
_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>finddevguides</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_entitiesl_としてサーバーパスに保存します(このファイルとaddress_internal_dtd.xmlはサーバーの同じパスにある必要があります)。 次のように出力を取得します-
Nodename is: #document
nodetype is: 9
Nodename is: address
nodetype is: 1