Browse By Name
HTMLCSSJavaScriptAppendix
You are here: Reference > JavaScript > client-side > HTML DOM > methods > createDocumentType (implementation)

createDocumentType method (implementation)

A A Font size Print Content Add new content Share Share
Browser support:
Creates a new doctype object.
When the new doctype object is created, it can be used for the createDocument method to specify the document type for a new XML document or it can be inserted into an XML document with the insertBefore or replaceChild method.

Syntax:

object.createDocumentType (qualifiedName, publicID, systemID);
You can find the related objects in the Supported by objects section below.

Parameters:

qualifiedName
Required. String that specifies the name of the document type.
publicID
Required. String that specifies the public identifier for the document type element.
systemID
Required. String that specifies the system identifier for the document type element.

Return value:

Returns the newly created doctype object.

Example HTML code 1:

This example illustrates the use of the createDocumentType method:
<head>
    <script>
        function CreateXMLDoc () {
            if (document.implementation.createDocument && 
                document.implementation.createDocumentType) 
            {
                var fruitDocType = document.implementation.createDocumentType ("fruit", "SYSTEM", "<!ENTITY tf 'tropical fruit'>");
                var xmlDoc = document.implementation.createDocument ("", "fruits", fruitDocType);

                var fruitNode = xmlDoc.createElement ("fruit");
                fruitNode.setAttribute ("name" , "avocado");
                xmlDoc.documentElement.appendChild (fruitNode);
                
                if (typeof (XMLSerializer) != "undefined") {
                    var serializer = new XMLSerializer();
                    alert(serializer.serializeToString(xmlDoc));
                }
            }
            else {
                alert ("Your browser does not support this example");
            }
        }

    </script>
</head>
<body>
    <button onclick="CreateXMLDoc ();">Create an XML document with document type!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content