The createDocument() method of the DOMImplementation interface creates and returns an XMLDocument.
createDocument(namespaceURI, qualifiedName)
createDocument(namespaceURI, qualifiedName, documentType)namespaceURIA string containing the namespace URI of the document to be created, or null if the document doesn't belong to one.
qualifiedNameA string containing the qualified name of the document to be created. A null value is treated the same as the empty string ("").
The format of the qualified name is prefix:localName or localName, where the parts are defined as:
prefix OptionalA "short alias" for the namespace. The prefix is optional, but if it is specified the namespaceURI parameter must also be specified. If the prefix is set to xml or xmlns, the namespaceURI must be set to http://www.w3.org/XML/1998/namespace or http://www.w3.org/2000/xmlns/, respectively. Defaults to null.
localNameThe local name of the document.
documentType OptionalThe DocumentType of the document to be created. It defaults to null.
The newly-created XMLDocument.
NamespaceError DOMExceptionThrown if the namespaceURI value is:
prefix has a value.http://www.w3.org/XML/1998/namespace or http://www.w3.org/2000/xmlns/ when prefix is set to xml or xmlns, respectively.InvalidCharacterError DOMExceptionThrown if either the prefix or localName is not valid:
prefix must have at least one character, and cannot contain ASCII whitespace, NULL, /, or > (U+0000, U+002F, or U+003E, respectively).localName is a valid element name if it has a length of at least 1 and:NULL, /, or > (U+0000, U+002F, or U+003E, respectively).: (U+003A), _ (U+005F), or any characters in the range U+0080 to U+10FFFF (inclusive), and the remaining code points only include those same characters along with the ASCII alphanumeric characters, - (U+002D), and . (U+002E),Note: Earlier versions of the specification were more restrictive, requiring that the qualifiedName be a valid XML name.
const doc = document.implementation.createDocument(
"http://www.w3.org/1999/xhtml",
"html",
null,
);
const body = document.createElementNS("http://www.w3.org/1999/xhtml", "body");
body.setAttribute("id", "abc");
doc.documentElement.appendChild(body);
alert(doc.getElementById("abc")); // [object HTMLBodyElement]DOMImplementation interface it belongs to.