You are here: Reference > JavaScript > client-side > HTML DOM > methods > createDocument (implementation)
createDocument method (implementation)
9 | ||||
Creates an XML document object.
Note: The createDocument method is supported in Internet Explorer from version 9, but it creates an HTML document, not an XML document.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the namespace URI for the documentElement (root node). | |||||||
Required. String that specifies the name of the documentElement (root node). If an empty string is specified, the new XML document will have no root node. | |||||||
Required. Reference to a doctype object that specifies the document type of the XML document. Use the createDocumentType method to create a doctype object. Set to null if no document type is needed. |
Return value:
Returns the newly created XMLDocument object.
Example HTML code 1:
This example illustrates the use of the createDocument method:
|
||||
<head> <script type="text/javascript"> 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); 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?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments