XML DOM | createDocument Method

XML DOM - createdocument Method


Hello folks! welcome back to a new edition of our tutorial on XML DOM. In this tutorial, we are going to be studying about the XML DOM createDocument Method.

The XML DOM createDocument method is used to create a DOM Document object of a specified type with its document element.

Syntax

The following below is the syntax to use the XML DOM createdocument Method -

Document doc = document.implementation.createDocument
   (namespaceURI, qualifiedNameStr, documentType);


Parameter Details

  • namespaceURI is the namespace URI of the document element to be created or null.
  • qualifiedName is the qualified name of the document element to be created or null.
  • doctype is the type of document to be created or null.
  • This method returns a new Document object with its document element.

Example

The following example illustrates the usage of the createDocument method -

<!DOCTYPE html>
<html>
   <body>
      <script>
         var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 
            'html', null);
         var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
         body.setAttribute('id', 'Company');
         doc.documentElement.appendChild(body);
         document.write(doc.getElementById('Company')); // [object HTMLBodyElement]
      </script>
   </body>
</html>

Output

Save this file as domimplementation_createdocument.html on the server path (this file and node.xml should be on the same path in your server). This gives us the following output below -

[object HTMLBodyElement]


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we will be studying about XML DOM createDocumentType Method.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.