DOM - 实体对象属性 - publicId
属性 publicId 返回关联实体的公共标识符或返回 null。
语法
以下是使用 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>
执行
将此文件另存为服务器路径上的 entity_publicid.html(此文件和 notation.xml 应位于服务器中的同一路径)。我们将获得如下所示的输出 −
publicid : -//W3C//DTD XHTML 1.1//EN
dom_entity_object.htm