The DocumentType Interface

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

<!DOCTYPE mml:math PUBLIC "-//W3C//DTD MathML 2.0//EN"
 "http://www.w3.org/TR/MathML2/dtd/mathml2.dtd" [
  <!ENTITY % MATHML.prefixed "INCLUDE">
  <!ENTITY % MATHML.prefix "mml">
]>

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

It’s important to note that the document type declaration is not the same thing as the document type definition. The document type declaration points to the document type definition, and may sometime contain the document type defintion 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.

Example 11.21 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.

Example 11.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.


Copyright 2001, 2002 Elliotte Rusty Haroldelharo@metalab.unc.eduLast Modified July 29, 2002
Up To Cafe con Leche