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"   "http://www.w3.org/TR/MathML2/dtd/mathml2.dtd" [   <!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 ( http://www.w3.org/TR/MathML2/dtd/mathml2.dtd 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.

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.



Processing XML with Java. A Guide to SAX, DOM, JDOM, JAXP, and TrAX
Processing XML with Javaв„ў: A Guide to SAX, DOM, JDOM, JAXP, and TrAX
ISBN: 0201771861
EAN: 2147483647
Year: 2001
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net