nu.xom
Class DocType

java.lang.Object
  extended bynu.xom.Node
      extended bynu.xom.LeafNode
          extended bynu.xom.DocType

public class DocType
extends LeafNode

This class represents an XML document type declaration such as

<!DOCTYPE book SYSTEM "docbookx.dtd">

Note that this is not the same thing as a document type definition (DTD). XOM does not currently model the DTD. The document type declaration contains or points to the DTD, but it is not the DTD.

A DocType object does not have any child nodes. It can be a child of a Document.

Each DocType object has four properties, some of which may be null:

The first three properties are read-write. The internal DTD subset is read-only. XOM fills it in when a document is read by a parser. However, it cannot be changed, because XOM cannot currently check that an internal DTD subset is well-formed. This restriction may be relaxed in a future version.

Version:
1.0d23
Author:
Elliotte Rusty Harold

Constructor Summary
DocType(DocType doctype)
           Creates a new DocType that's a copy of its argument.
DocType(java.lang.String rootElementName)
           Creates a new document type declaration with no public or system ID.
DocType(java.lang.String rootElementName, java.lang.String systemID)
           Creates a new document type declaration with a system ID but no public ID.
DocType(java.lang.String rootElementName, java.lang.String publicID, java.lang.String systemID)
           Creates a new document type declaration with a system ID and a public ID It has the general form <!DOCTYPE rootElementName PUBLIC "publicID" "systemID">.
 
Method Summary
protected  void checkPublicID(java.lang.String publicID)
           Subclasses can override this method to perform additional checks on the system ID beyond what XML 1.0 requires.
protected  void checkRootElementName(java.lang.String name)
           Subclasses can override this method to perform additional checks on the root element name beyond what XML 1.0 requires.
protected  void checkSystemID(java.lang.String systemID)
           Subclasses can override this method to perform additional checks on the system ID beyond what XML 1.0 requires.
 Node copy()
           This method returns a copy of this DocType which has the same system ID, public ID, root element name, and internal DTD subset, but does not belong to a document.
 java.lang.String getInternalDTDSubset()
           Returns complete internal DTD subset in a single string.
 java.lang.String getPublicID()
           Returns the public ID of the external DTD subset.
 java.lang.String getRootElementName()
           Returns the name the document type declaration specifies for the root element.
 java.lang.String getSystemID()
           Returns the system ID of the external DTD subset.
 java.lang.String getValue()
           Returns the empty string.
 void setPublicID(java.lang.String id)
           Sets the public ID for the external DTD subset.
 void setRootElementName(java.lang.String name)
           Sets the name the document type declaration specifies for the root element.
 void setSystemID(java.lang.String id)
           Sets the system ID for the external DTD subset.
 java.lang.String toString()
           This method returns a string form of the DocType suitable for debugging and diagnosis.
 java.lang.String toXML()
           Returns a string containing the actual XML form of the document type declaration represented by this object; for example, <!DOCTYPE book SYSTEM "docbookx.dtd">.
 
Methods inherited from class nu.xom.LeafNode
getChild, getChildCount, hasChildren
 
Methods inherited from class nu.xom.Node
checkDetach, detach, equals, getBaseURI, getDocument, getParent, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DocType

public DocType(java.lang.String rootElementName,
               java.lang.String publicID,
               java.lang.String systemID)

Creates a new document type declaration with a system ID and a public ID It has the general form <!DOCTYPE rootElementName PUBLIC "publicID" "systemID">.

Parameters:
rootElementName - the name specified for the root element
publicID - the public ID of the external DTD subset
systemID - the URL of the external DTD subset
Throws:
IllegalNameException - if rootElementName is not a legal XML 1.0 name
IllegalDataException - if systemID is not a legal XML 1.0 system literal or publicID is not a legal XML 1.0 public identifier

DocType

public DocType(java.lang.String rootElementName,
               java.lang.String systemID)

Creates a new document type declaration with a system ID but no public ID. It has the general form <!DOCTYPE rootElementName SYSTEM "systemID">.

Parameters:
rootElementName - the name specified for the root element
systemID - the URL of the external DTD subset
Throws:
IllegalNameException - if the rootElementName is not a legal XML 1.0 name
IllegalDataException - if the system ID is not a legal XML 1.0 system literal

DocType

public DocType(java.lang.String rootElementName)

Creates a new document type declaration with no public or system ID. It has the general form <!DOCTYPE rootElementName >.

Parameters:
rootElementName - the name specified for the root element
Throws:
IllegalNameException - if the rootElementName is not a legal XML 1.0 name

DocType

public DocType(DocType doctype)

Creates a new DocType that's a copy of its argument. The copy has the same data but no parent document.

Parameters:
doctype - the DocType to copy
Method Detail

setRootElementName

public final void setRootElementName(java.lang.String name)

Sets the name the document type declaration specifies for the root element. In an invalid document, this may not be the same as the actual root element name.

Parameters:
name - the root element name given by the document type declaration
Throws:
IllegalNameException - if the rootElementName is not a legal XML 1.0 name

getRootElementName

public final java.lang.String getRootElementName()

Returns the name the document type declaration specifies for the root element. In an invalid document, this may not be the same as the actual root element name.

Returns:
the declared name of the root element

getInternalDTDSubset

public final java.lang.String getInternalDTDSubset()

Returns complete internal DTD subset in a single string. White space may not be preserved completely accurately, but all declarations should be in place.

Returns:
the internal DTD subset

setPublicID

public final void setPublicID(java.lang.String id)

Sets the public ID for the external DTD subset. This can only be set after a system ID has been set, because XML requires that all document type declarations with public IDs have system IDs. Passing null removes the public ID.

Parameters:
id - the public identifier of the external DTD subset
Throws:
IllegalDataException - if the public ID does not satisfy the rules for public IDs in XML 1.0
WellformednessException - if no system ID has been set

getPublicID

public final java.lang.String getPublicID()

Returns the public ID of the external DTD subset. This is null if there is no external DTD subset or if it does not have a public identifier.

Returns:
the public ID of the external DTD subset.

setSystemID

public final void setSystemID(java.lang.String id)

Sets the system ID for the external DTD subset. This is normally a relative or absolute URL. Passing null removes the system ID, but only if the public ID has been removed first. Otherwise, passing null causes a WellformednessException.

Parameters:
id - the URL of the external DTD subset
Throws:
IllegalDataException - if the system ID is not a legal XML 1.0 system literal
WellformednessException - if the public ID is non-null and you attempt to remove the system ID

getSystemID

public final java.lang.String getSystemID()

Returns the system ID of the external DTD subset. This is a URL. It is null if there is no external DTD subset.

Returns:
the URL for the external DTD subset.

checkRootElementName

protected void checkRootElementName(java.lang.String name)

Subclasses can override this method to perform additional checks on the root element name beyond what XML 1.0 requires. For example, an HTMLDocType subclass might throw an exception if any name other than "html" were passed to this method. However, this can only be used to add checks, not remove them. All document type declarations must be potentially well-formed when serialized.

Parameters:
name - The root element name specified by the document type declaration.
Throws:
XMLException - if the proposed root element name does not satisfy the local constraints

checkSystemID

protected void checkSystemID(java.lang.String systemID)

Subclasses can override this method to perform additional checks on the system ID beyond what XML 1.0 requires. For example, it might wish to check that the URL scheme is recognized. However, this can only be used to add checks, not remove them. All document type declarations must be potentially well-formed when serialized.

Parameters:
systemID - The URL of the external DTD subset.
Throws:
XMLException - if the proposed system ID does not satisfy the local constraints

checkPublicID

protected void checkPublicID(java.lang.String publicID)

Subclasses can override this method to perform additional checks on the system ID beyond what XML 1.0 requires. For example, an HTMLDocType subclass might check that the public ID were one of the three IDs defined by the XHTML 1.0 specification. However, this can only be used to add checks, not remove them. All document type declarations must be potentially well-formed when serialized.

Parameters:
publicID - The proposed public ID for the external DTD subset.
Throws:
XMLException - if the proposed public ID does not satisfy the local constraints

getValue

public final java.lang.String getValue()

Returns the empty string. XPath 1.0 does not define a value for document type declarations.

Specified by:
getValue in class Node
Returns:
an empty string
See Also:
Node.getValue()

toString

public final java.lang.String toString()

This method returns a string form of the DocType suitable for debugging and diagnosis. It deliberately does not return an actual XML document type declaration.

Specified by:
toString in class Node
Returns:
a string representation of the object
See Also:
Node.toString()

copy

public Node copy()

This method returns a copy of this DocType which has the same system ID, public ID, root element name, and internal DTD subset, but does not belong to a document. Thus, it can be inserted into a different document.

Specified by:
copy in class Node
Returns:
a deep copy of this DocType that is not part of a document
See Also:
Node.copy()

toXML

public final java.lang.String toXML()

Returns a string containing the actual XML form of the document type declaration represented by this object; for example, <!DOCTYPE book SYSTEM "docbookx.dtd">.

Specified by:
toXML in class Node
Returns:
a String containing an XML document type declaration
See Also:
Node.toXML()


Copyright 2002-2004 Elliotte Rusty Harold
elharo@metalab.unc.edu