The DocumentType Interface

The DocumentType Interface

The DocumentType interface represents a document's document type declaration. That is, it's the in-memory representation of the following construct:

<!DOCTYPE mml:math PUBLIC "-//W3C//DTD MathML 2.0//EN" 
 "" [
  <!ENTITY % MATHML.prefixed "INCLUDE">
  <!ENTITY % MATHML.prefix "mml">

Each document type declaration has four parts, three of which are optional:

  1. The root element name (mml:math in the above example)

  2. The public ID (-//W3C//DTD MathML 2.0//EN in the above example)

  3. The system ID ( in the above example)

  4. The internal DTD subset (everything between the [ and the ])

It's important to note that the document type declaration is not the same thing as the document type definition (DTD). The document type declaration points to the DTD, and may sometimes contain the document type definition or part of it as the internal DTD subset. However, the document type declaration and the document type definition are two different things. DOM2 only provides access to the document type declaration; it does not tell you what the document type definition says. The acronym DTD is used only for the document type definition.

Figure summarizes DOM's DocumentType interface. It has methods to get the root element name, the public ID, the system ID, the internal DTD subset, and maps of the entities and notations declared in the DTD this document type declaration points to.

21 The DocumentType Interface
package org.w3c.dom;

public interface DocumentType extends Node {

  public String       getName();
  public NamedNodeMap getEntities();
  public NamedNodeMap getNotations();
  public String       getPublicId();
  public String       getSystemId();
  public String       getInternalSubset();


All of these properties are read only. That is, there are getter methods but no corresponding setter methods. You cannot change the name, public ID, system ID, or anything else about a DocumentType object. Once the parser has read it, it's final.

A DocumentType object is created by a DOMImplementation object and assigned to a document when the Document object is created. After that point, a document's DocumentType cannot be changed.

The next two sections will provide some examples of this interface.

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows