XML technologies / XML / XML in a Nutshell / DOM reference / Object reference / DOMImplementation
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
The interface DOMImplementation provides information about the particular DOM implementation currently in use. A reference to the interface DOMImplementation can be obtained only through the method getImplementation( ) of the Document object.
Java example
// Prüfe, ob DOM Level 1 unterstützt wird.
DOMImplementation di = doc.getImplementation( );
// Stelle sicher, dass DOM Level 1 unterstützt wird.
if (!di.hasFeature("XML", "1.0")) {
return null;
}
Attributes
The object DOMImplementation has no attributes.
Methods
The DOMImplementation object supports the following methods:
createDocument: namespaceURI, qualifiedName, doctype (2)
Creates a new empty Document object with the specified document type. The document is created with a single document element having the specified qualified name and associated namespace URI.
Arguments
namespaceURI: DOMString
The URI of the namespace for the document element. May be
nullif no namespace is used.qualifiedName: DOMString
The fully qualified name of the document element to create. The prefix specified in this parameter is associated with the URI in the parameter
namespaceURI.doctype: DOMString
The DTD to which the new document must conform. If this parameter is not
null, the attributeownerDocumentof the supplied object of typeDocumentTypeis set to the new document.
Exceptions
INVALID_CHARACTER_ERR
The supplied parameter
qualifiedNamecontains an invalid XML identifier.NAMESPACE_ERR
This exception indicates an inconsistency between the parameters
namespaceURIandqualifiedName. For example, a qualified name with a namespace prefix cannot be supplied without a namespace URI. This exception is also raised when the reserved prefix"xml"is specified with an invalid namespace URI.WRONG_DOCUMENT_ERR
Raised if the
doctypeparameter supplies aDocumentTypenode already associated with another document. NewDocumentTypeobjects must first be created with the methodcreateDocumentTypeof the interfaceDOMImplementation.
Java binding
public Document createDocument(String namespaceURI,
String qualifiedName, DocumentType doctype) throws DOMException;
createDocumentType: qualifiedName, publicId, systemId (2)
Creates an empty DocumentType node not associated with any document. The new DocumentType object contains neither entity declarations nor notations. The current DOM version offers no way to change this.
Arguments
qualifiedName: DOMString
The fully qualified name of the document type to create.
publicId: DOMString
The PUBLIC identifier of the external subset.
systemId: DOMString
The SYSTEM identifier, as a URI, of the external subset to create.
Return value
A new DocumentType object whose ownerDocument attribute has the value null.
Exceptions
INVALID_CHARACTER_ERR
The parameter
qualifiedNamecontains an invalid XML identifier.NAMESPACE_ERR
Raised if the qualified name is not well-formed.
Java binding
public DocumentType createDocumentType(String qualifiedName,
String publicId, String systemId) throws DOMException;
getFeature: feature, version (3)
Provides a binding-independent way to retrieve an object instance implementing a particular version of a feature. Mainly used to access features beyond DOM Core.
Arguments
feature: DOMString
The package name of the feature to retrieve.
version: DOMString
The DOM version level of the feature to retrieve.
Return value
Returns an object implementing the APIs for the specified feature, or null, if no implementation is available.
Java binding
public Object getFeature(String feature, String version);
hasFeature: feature, version
Checks whether the DOM implementation supports a particular version of the specified feature.
Arguments
feature: DOMString
The name of the feature to check. The following feature names are currently valid, along with the other names listed under What is the Document Object Model?:
XML
Support for DOM Core version 1.0 or 2.0.
HTML
Support for the HTML objects in extended DOM 1.0 or 2.0.
version: DOMString
The version that must be supported. If no version number is specified, the function returns
trueif any version is supported.
Return values
Returns true, if the specified version of the feature is available. Otherwise, it returns false.
Java binding
public boolean hasFeature(String feature, String version);
Java example
// Prüfe, ob DOM Level 1.0 unterstützt wird.
if (!di.hasFeature("XML", "1.0")) {
return null;
}Note: We omit the HTML-specific part of DOM because HTML-oriented applications are outside this book’s scope. HTML objects are extremely useful, however, for applications that modify HTML documents. An excellent reference is the book Dynamic HTML: The Definitive Reference by Danny Goodman (O'Reilly & Associates).
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de