Package nu.xom

Class DocType


public class DocType extends Node

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 String properties, some of which may be null:

  • The declared name of the root element (which does not necessarily match the actual root element name in an invalid document)
  • The public identifier (which may be null)
  • The system identifier (which may be null)
  • The internal DTD subset (which may be null)
Version:
1.1d1
Author:
Elliotte Rusty Harold
  • Constructor Summary

    Constructors
    Constructor
    Description
    DocType(String rootElementName)
    Creates a new document type declaration with no public or system ID.
    DocType(String rootElementName, String systemID)
    Creates a new document type declaration with a system ID but no public ID.
    DocType(String rootElementName, String publicID, String systemID)
    Creates a new document type declaration with a public ID and a system ID.
    DocType(DocType doctype)
    Creates a new DocType that's a copy of its argument.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    final Node
    getChild(int position)
    Throws IndexOutOfBoundsException because document type declarations do not have children.
    final int
    Returns 0 because document type declarations do not have children.
    final String
    Returns the complete internal DTD subset.
    final String
    Returns the public ID of the external DTD subset.
    final String
    Returns the name the document type declaration specifies for the root element.
    final String
    Returns the system ID of the external DTD subset.
    final String
    Returns the empty string.
    final void
    Sets the internal DTD subset; that is the part of the DTD between [ and ].
    void
    Sets the public ID for the external DTD subset.
    void
    Sets the name the document type declaration specifies for the root element.
    void
    Sets the system ID for the external DTD subset.
    final String
    Returns a string form of the DocType suitable for debugging and diagnosis.
    final String
    Returns a string containing the actual XML form of the document type declaration represented by this object.

    Methods inherited from class nu.xom.Node

    detach, equals, getBaseURI, getDocument, getParent, hashCode, query, query

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DocType

      public DocType(String rootElementName, String publicID, String systemID)

      Creates a new document type declaration with a public ID and a system 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 publicID is not a legal XML 1.0 public identifier
      MalformedURIException - if the system ID is not a syntactically correct URI, or if it contains a fragment identifier
    • DocType

      public DocType(String rootElementName, 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
      MalformedURIException - if the system ID is not a syntactically correct URI, or if it contains a fragment identifier
    • DocType

      public DocType(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 Details

    • getRootElementName

      public final 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
    • setRootElementName

      public void setRootElementName(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 root element name is not a legal XML 1.0 name
    • getInternalDTDSubset

      public final String getInternalDTDSubset()

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

      Returns:
      the internal DTD subset
    • setInternalDTDSubset

      public final void setInternalDTDSubset(String subset)

      Sets the internal DTD subset; that is the part of the DTD between [ and ]. Changing the internal DTD subset does not affect the instance document. That is, default attribute values and attribute types specified in the new internal DTD subset are not applied to the corresponding elements in the instance document. Furthermore, there's no guarantee that the instance document is or is not valid with respect to the declarations in the new internal DTD subset.

      Parameters:
      subset - the internal DTD subset
      Throws:
      IllegalDataException - if subset is not a legal XML 1.0 internal DTD subset
      Since:
      1.1
    • getPublicID

      public final 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.
    • setPublicID

      public void setPublicID(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
    • getSystemID

      public final 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.
    • setSystemID

      public void setSystemID(String id)

      Sets the system ID for the external DTD subset. This must be a a relative or absolute URI with no fragment identifier. 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:
      MalformedURIException - if the system ID is not a syntactically correct URI, or if it contains a fragment identifier
      WellformednessException - if the public ID is non-null and you attempt to remove the system ID
    • getValue

      public final 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
    • getChild

      public final Node getChild(int position)

      Throws IndexOutOfBoundsException because document type declarations do not have children.

      Specified by:
      getChild in class Node
      Parameters:
      position - the index of the child node to return
      Returns:
      never returns because document type declarations do not have children. Always throws an exception.
      Throws:
      IndexOutOfBoundsException - because document type declarations do not have children
    • getChildCount

      public final int getChildCount()

      Returns 0 because document type declarations do not have children.

      Specified by:
      getChildCount in class Node
      Returns:
      zero
    • toString

      public final String toString()

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

      Overrides:
      toString in class Object
      Returns:
      a string representation of this object
    • copy

      public Node copy()

      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
    • toXML

      public final 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