DOM - Attribut d'objet de notation - publicID

L'identifiant public d'une notation ; ou null si aucun identifiant public n'est spécifié.

Syntaxe

Voici la syntaxe pour l'utilisation de l' attribut publicID .

var pubid = document.doctype.publicId;

Exemple

Le contenu de notation_xhtml.xml est comme ci-dessous -

<?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>
   <name>Tanmay Patil</name >
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</address>

L'exemple suivant montre l'utilisation de l' attribut 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("The publicId asscoiated with the notation is:"+ xmlDoc.doctype.publicId);
      </script>
   </body>
</html>

Exécution

Enregistrez ce fichier sous notationattribute_publicid.html sur le chemin du serveur (ce fichier et notation.xml doivent être sur le même chemin sur votre serveur). Nous obtiendrons la sortie comme indiqué ci-dessous -

The publicId asscoiated with the notation is: -//W3C//DTD XHTML 1.1//EN