DOM - DocumentType 对象属性 - publicId
属性 publicId 返回外部子集的公共标识符。
语法
以下是 publicId 属性用法的语法。
document.doctype.publicId;
示例
notation.xml 内容如下 −
<?xml version = "1.0" encoding = "UTF-8" standalone = "no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<address id = "firstelement">
<name>Tanmay Patil</name >
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</address>
以下示例演示了 publicId 属性的用法 −
<!DOCTYPE html>
<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/notation_xhtml.xml");
document.write("<b>publicid :</b> "+xmlDoc.doctype.publicId);
</script>
</body>
</html>
执行
将此文件另存为服务器路径上的 documenttype_publicid.html(此文件和 notation.xml 应位于服务器中的同一路径)。我们将获得如下所示的输出 −
publicid : -//W3C//DTD XHTML 1.1//EN
dom_documenttype_object.htm