The createDocument of DOMImplementation for JS returns an XMLDocument, with a document element whose local name is qualifiedName and whose namespace is namespace (unless qualifiedName is the empty string), and with doctype, if it is given, as its doctype.
This method throws the same exceptions as the createElementNS() method, when invoked with namespace and qualifiedName.
doc = document.implementation.createDocument(namespace, qualifiedName [, doctype = null]) A null or a non-empty string.
<!doctype html>
<html>
<body>
<script>
const namespace = "http://www.w3.org/2000/svg";
const qualifiedName = "svg";
const doc = document.implementation.createDocument(namespace, qualifiedName);
document.body.innerHTML = doc;
console.log(doc);
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<script>
const namespace = "uniform-resource-locator";
const qualifiedName = "top-element";
const publicId = "registration//organization//type label definition//language";
const systemId = "uniform-resource-locator";
const doctype = document.implementation.createDocumentType(qualifiedName, publicId, systemId);
const doc = document.implementation.createDocument(namespace, qualifiedName, doctype);
document.body.innerHTML = doc;
console.log(doc);
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<script>
const namespace = "http://www.w3.org/2000/svg";
const qualifiedName = "svg";
const publicId = "-//W3C//DTD SVG 1.1//EN";
const systemId = "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";
const doctype = document.implementation.createDocumentType(qualifiedName, publicId, systemId);
const doc = document.implementation.createDocument(namespace, qualifiedName, doctype);
document.body.innerHTML = doc;
console.log(doc);
</script>
</body>
</html>