4.3. The DTD classes

Sorry, not yet written. Perhaps the interface definition of Markup_dtd expresses the same:


(**********************************************************************)
(*                                                                    *)
(* Markup_dtd:                                                        *)
(*     Object model of document type declarations                     *)
(*                                                                    *)
(**********************************************************************)

(* ======================================================================
 * OVERVIEW
 *
 * class dtd ............... represents the whole DTD, including element
 *                           declarations, entity declarations, notation
 *                           declarations, and processing instructions
 * class dtd_element ....... represents an element declaration consisting
 *                           of a content model and an attribute list
 *                           declaration
 * class dtd_notation ...... represents a notation declaration
 * class proc_instruction .. represents a processing instruction
 * ======================================================================
 *
 *)


class dtd :
  (* Creation:
   *   new dtd
   * creates a new, empty DTD object without any declaration, without a root
   * element, without an ID.
   *)
  Markup_types.collect_warnings -> 
  object
    method root : string option
      (* get the name of the root element if present *)

    method set_root : string -> unit
      (* set the name of the root element. This method can be invoked 
       * only once
       *)

    method id : Markup_types.dtd_id option
      (* get the identifier for this DTD *)

    method set_id : Markup_types.dtd_id -> unit
      (* set the identifier. This method can be invoked only once *)


    method allow_arbitrary : unit
      (* After this method has been invoked, the object changes its behaviour:
       * - elements and notations that have not been added may be used in an
       *   arbitrary way; the methods "element" and "notation" indicate this
       *   by raising Undeclared instead of Validation_error.
       *)

    method disallow_arbitrary : unit

    method arbitrary_allowed : bool
      (* Returns whether arbitrary contents are allowed or not. *)

    method add_element : dtd_element -> unit
      (* add the given element declaration to this DTD. Raises Not_found
       * if there is already an element declaration with the same name.
       *)

    method add_gen_entity : Markup_entity.entity -> unit
      (* add the given entity as general entity to this DTD (general entities
       * are those represented by &name;). If there is already a declaration
       * with the same name, the second definition is ignored; as exception from
       * this rule, entities with names "lt", "gt", "amp", "quot", and "apos"
       * may only be redeclared with a definition that is equivalent to the
       * standard definition; otherwise a Validation_error is raised.
       *)

    method add_par_entity : Markup_entity.entity -> unit
      (* add the given entity as parameter entity to this DTD (parameter
       * entities are those represented by %name;). If there is already a 
       * declaration with the same name, the second definition is ignored.
       *)

    method add_notation : dtd_notation -> unit
      (* add the given notation to this DTD. If there is already a declaration
       * with the same name, a Validation_error is raised.
       *)

    method add_pinstr : proc_instruction -> unit
      (* add the given processing instruction to this DTD. *)

    method element : string -> dtd_element
      (* looks up the element declaration with the given name. Raises 
       * Validation_error if the element cannot be found. (If "allow_arbitrary"
       * has been invoked before, Unrestricted is raised instead.)
       *)

    method element_names : string list
      (* returns the list of the names of all element declarations. *)

    method gen_entity : string -> Markup_entity.entity
      (* looks up the general entity with the given name. Raises
       * Validation_error if the entity cannot be found.
       *)

    method par_entity : string -> Markup_entity.entity
      (* looks up the parameter entity with the given name. Raises
       * Validation_error if the entity cannot be found.
       *)

    method notation : string -> dtd_notation
      (* looks up the notation declaration with the given name. Raises
       * Validation_error if the notation cannot be found. (If "allow_arbitrary"
       * has been invoked before, Unrestricted is raised instead.)
       *)

    method notation_names : string list
      (* Returns the list of the names of all added notations *)

    method pinstr : string -> proc_instruction list
      (* looks up all processing instructions with the given target.
       * The "target" is the identifier following "<?".
       * Note: It is not possible to find out the exact position of the
       * processing instruction.
       *)

    method pinstr_names : string list
      (* Returns the list of the names (targets) of all added pinstrs *)

    method validate : unit
      (* ensures that the DTD is valid. This method is optimized such that
       * actual validation is only performed if DTD has changed.
       * If the DTD is invalid, mostly a Validation_error is raised,
       * but other exceptions are possible, too.
       *)

    method write_compact_as_latin1 : Markup_types.output_stream -> bool -> unit
      (* write_compact_as_latin1 os doctype:
       * Writes the DTD as Latin 1 string to 'os'. If 'doctype', a 
       * DTD like <!DOCTYPE root [ ... ]> is written. If 'not doctype',
       * only the declarations are written (the material within the
       * square brackets).
       *)


    (*----------------------------------------*)
    method invalidate : unit
      (* INTERNAL METHOD *)
    method warner : Markup_types.collect_warnings
      (* INTERNAL METHOD *)
  end



(* ---------------------------------------------------------------------- *)

and dtd_element : dtd -> string ->
  (* Creation:
   *   new dtd_element a_dtd a_name
   * creates a new dtd_element object for a_dtd with a_name
   *)
  object

    method name : string
      (* returns the name of the declared element *)

    method content_model : Markup_types.content_model_type
      (* get the content model of this element declaration, or Unspecified *)

    method set_content_model : Markup_types.content_model_type -> unit
      (* set the content model. Once the content model is not Unspecified,
       * it cannot be set to a different value again.
       *)

    method allow_arbitrary : unit
      (* After this method has been invoked, the object changes its behaviour:
       * - attributes that have not been added may be used in an
       *   arbitrary way; the method "attribute" indicates this
       *   by raising Undeclared instead of Validation_error.
       *)

    method disallow_arbitrary : unit

    method arbitrary_allowed : bool
      (* Returns whether arbitrary attributes are allowed or not. *)

    method attribute : string -> 
                         Markup_types.att_type * Markup_types.att_default
      (* get the type and default value of a declared attribute, or raise
       * Validation_error if the attribute does not exist.
       * If 'arbitrary_allowed', the exception Undeclared is raised instead
       * of Validation_error.
       *)

    method attribute_names : string list
      (* get the list of all declared attributes *)

    method names_of_required_attributes : string list
      (* get the list of all attributes that are specified as required 
       * attributes
       *)

    method add_attribute : string -> 
                           Markup_types.att_type -> 
			   Markup_types.att_default -> 
			     unit
      (* add an attribute declaration for an attribute with the given name,
       * type, and default value. If there is more than one declaration for
       * an attribute name, the first declaration counts; the other declarations
       * are ignored.
       *)

    method validate : unit
      (* checks whether this element declaration (i.e. the content model and
       * all attribute declarations) is valid for the associated DTD.
       * Raises mostly Validation_error if the validation fails.
       *)

    method write_compact_as_latin1 : Markup_types.output_stream -> unit
      (* write_compact_as_latin1 os:
       * Writes the <!ELEMENT ... > declaration to 'os' as Latin 1 string.
       *)

  end

(* ---------------------------------------------------------------------- *)

and dtd_notation : string -> Markup_types.ext_id ->
  (* Creation:
   *    new dtd_notation a_name an_external_ID
   * creates a new dtd_notation object with the given name and the given
   * external ID.
   *)
  object
    method name : string
    method ext_id : Markup_types.ext_id

    method write_compact_as_latin1 : Markup_types.output_stream -> unit
      (* write_compact_as_latin1 os:
       * Writes the <!NOTATION ... > declaration to 'os' as Latin 1 string.
       *)

  end

(* ---------------------------------------------------------------------- *)

and proc_instruction : string -> string ->
  (* Creation:
   *   new proc_instruction a_target a_value
   * creates a new proc_instruction object with the given target string and
   * the given value string. 
   * Note: A processing instruction is written as <?target value?>. 
   *)
  object
    method target : string
    method value : string

    method write_compact_as_latin1 : Markup_types.output_stream -> unit
      (* write_compact_as_latin1 os:
       * Writes the <?...?> PI to 'os' as Latin 1 string.
       *)

  end

;;