XML technologies / XML / XML in a Nutshell / DOM reference / Object reference / DocumentType
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
The interface Document contains a single docType attribute. Its value refers to a description in the DTD of the current document (a DocumentType object), or to null, if none is available.
Java example
// Lies Information über den Dokumenttyp.
DocumentType dtDoc = doc.getDoctype( );
Attributes
The object DocumentType has the following attributes:
entities: NamedNodeMap
This attribute contains a list of all general entities declared in the DTD. If an entity is declared more than once in the DTD, the NamedNodeMap contains only the first instance. Note that declarations of parameter entities cannot be accessed through the DocumentType interface. All list entries are instances of the interface Entity. Read-only.
Java binding
public NamedNodeMap getEntities( );
Java example
// Ausgabe aller Entities
NamedNodeMap nnm = doc.getDoctype().getEntities( );
Entity ndEnt;
for (int i = 0; i < nnm.getLength( ); i++) {
ndEnt = (Entity)nnm.item(i);
System.out.println(ndEnt.getNodeName( ));
if (ndEnt.getPublicId( ) != null) {
System.out.println("\tPublic Identifier: " +
ndEnt.getPublicId( ));
}
if (ndEnt.getSystemId( ) != null) {
System.out.println("\tSystem Identifier: " +
ndEnt.getSystemId( ));
}
if (ndEnt.getNotationName( ) != null) {
System.out.println("\tNotation Name: " +
ndEnt.getNotationName( ));
}
}
internalSubset: DOMString
This attribute contains the internal DTD subset as a string. The exact format depends on how fully the particular XML parser supports this feature. Read-only.
Java binding
public String getInternalSubset( );
name: DOMString
The DTD name, that is, the XML name following the keyword DOCTYPE in the parsed XML document. Read-only.
Java binding
public String getName( );
Java example
// Ausgabe von Informationen über den Dokumenttyp
DocumentType dtDoc = doc.getDoctype( );
System.out.println("This is a " + dtDoc.getName( ) + " document.");
notations: NamedNodeMap
A NamedNodeMap contains a list of XML notation declarations valid in the current document. Each list entry implements the interface Notation. The list itself is read-only.
Java binding
public NamedNodeMap getNotations( );
Java example
// Ausgabe der im Dokument gültigen Notationen
NamedNodeMap nnm = doc.getDoctype().getNotations( );
Notation ndNotation;
for (int i = 0; i < nnm.getLength( ); i++) {
ndNotation = (Notation)nnm.item(i);
System.out.println(ndNotation.getNodeName( ));
if (ndNotation.getPublicId( ) != null) {
System.out.println("\tPublic Identifier: " +
ndNotation.getPublicId( ));
}
if (ndNotation.getSystemId( ) != null) {
System.out.println("\tSystem Identifier: " +
ndNotation.getSystemId( ));
}
}
publicId: DOMString
The PUBLIC identifier of the external subset. Read-only.
Java binding
public String getPublicId( );
systemId: DOMString
The SYSTEM identifier (a URI) of the external subset. Read-only.
Java binding
public String getSystemId( );
Methods
The object DocumentType has no methods.
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