Home to Document Object Model | Up to Core
Prev DOMException | Next NamedNodeMap


DOMImplementation
Object

This object allows for "meta-operations" - i.e. those outside the scope of a particular document instance.

The standard does not define how the implementation provides this object. The following should be portable but does not support access to multiple implementations:

var DOMImplementation = document.implementation;

hasFeature
Method
ECMAScript binding: hasFeature(feature, version) (returns Boolean; all parameters are strings)

See Document Object Model for a list of the features that can be tested. version should be "2.0" for the current version or "1.0" to test for DOM1 compliance. The method will return "true" if the feature is supported by the implementation at the given version.

createDocumentType
Method (only present if feature "XML" is present at version "2.0")
ECMAScript binding: createDocumentType(qualifiedName, publicId, systemId) (returns DocumentType; all parameters are strings; can raise DOMException)

Creates a DocumentType object for a particular DTD. qualifiedName, publicId and systemId refer to the parameters to the !DOCTYPE directive. For example,

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "/usr/lib/DTDs/docbkx412/DOCBOOKX.DTD">
could be expressed as
var DOMImplementation = document.implementation;
var bookType = DOMImplementation.createDocumentType("book", "-//OASIS//DTD DocBook XML V4.1.2//EN", "/usr/lib/DTDs/docbkx412/DOCBOOKX.DTD");
Note that, here, book is a local name within the default namespace.

Also note there's no way of creating <!ENTITY> references (that is, you can't script something like this:

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "/usr/lib/DTDs/docbkx412/DOCBOOKX.DTD"[
<!ENTITY chp1 "chp1.xml">
]>
). This may be available in a subsequent version.

The exceptions thrown are:

INVALID_CHARACTER_ERR
qualifiedName contains an illegal character.
NAMESPACE_ERR
qualfiedName is otherwise malformed.

createDocument
Method (only present if feature "XML" is present at version "2.0")
ECMAScript binding: createDocument(namespaceURI, qualifiedName, doctype) (returns Document; namespaceURI and qualifiedName are strings, doctype is a DocumentType; can raise DOMException)

This creates a new Document object of the given doctype. The namespaceURI should be the reference for the namespace prefix for the qualifiedName; it can be null if no namespace prefix is supplied on qualifiedName. Note that doctype is made a child of the Document object created.

A brief code sample:

var DOMImplementation = document.implementation;
var bookType = DOMImplementation.createDocumentType("book", "-//OASIS//DTD DocBook XML V4.1.2//EN", "/usr/lib/DTDs/docbkx412/DOCBOOKX.DTD");
var doc = DOMImplementation.createDocument(null, "book", bookType);
is equivalent to
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "/usr/lib/DTDs/docbkx412/DOCBOOKX.DTD">
<book/>

The exceptions thrown are:

INVALID_CHARACTER_ERR
qualifiedName contains an illegal character.
NAMESPACE_ERR
qualfiedName is otherwise malformed (e.g. has a prefix but the namespaceURI is null).
WRONG_DOCUMENT_ERR
doctype is referenced in another Document object or was created under a different DOMImplementation.

Log in or register to write something here or to contact authors.