We now have a youtube channel. Subscribe!

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.


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.


The following example illustrates the usage of the createDocument method -

<!DOCTYPE html>
         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');
         document.write(doc.getElementById('Company')); // [object HTMLBodyElement]


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.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain