(***********************************************************************)
(*                                                                     *)
(*                                 GALAX                               *)
(*                            XML Query Engine                         *)
(*                                                                     *)
(*  Copyright 2001-2003, Lucent Technologies.                          *)
(*  Distributed only by permission.                                    *)
(*                                                                     *)
(***********************************************************************)

(* $Id: sax_types.mli,v 1.4 2003/06/16 15:34:34 simeon Exp $ *)

(* Module: Sax_types
   Description:
     This module contains data structures for XML streams.
*)


(**********************************)
(* SAX events for well-formed XML *)
(**********************************)

(* XML declaration *)

type sax_xml_decl =
    (Datatypes.xdt_untyped * Glx_pxp.encoding option * Datatypes.xdt_untyped option)

(* DTD declaration *)

type sax_dtd_decl = unit option (* Note: The DTD is kept empty for now - Jerome *)

(* Attributes *)

type sax_xml_attribute =
    Namespace.uqname * Datatypes.xdt_untyped

type sax_xml_attribute_forest =
    sax_xml_attribute list

(* Elements, PIs, Comments, and Characters *)

type has_element_content = bool

type element_desc = Namespace.uqname * sax_xml_attribute_forest * has_element_content
type pi_desc      = Namespace.ncname * Datatypes.xdt_untyped
type comment_desc = Datatypes.xdt_untyped
type text_desc    = Datatypes.xdt_untyped

(* SAX events *)

type sax_event =
  | SAX_startDocument of sax_xml_decl option * sax_dtd_decl
  | SAX_endDocument
  | SAX_startElement of element_desc
  | SAX_endElement
  | SAX_processingInstruction of pi_desc
  | SAX_comment of comment_desc
  | SAX_characters of text_desc
  | SAX_attribute of sax_xml_attribute        (* Addition to the standard SAX events *)
  | SAX_atomicValue of Datatypes._AtomicValue (* Addition to the standard SAX events *)

(* Note:
     The two last events are added in order to be able to deal
     with top-level attributes and atomic values from the XQuery data
     model.
   - Jerome *)

(* Well-formed XML streams *)

(* Note:
     An XML stream is a Caml stream of SAX events. Please see the
     Stream Caml module for more on operations on streams.
   - Jerome *)

type xml_stream = sax_event Stream.t


(****************************)
(* SAX events for typed XML *)
(****************************)

(* Note:
     The following structures are used to represent 'typed' XML
     document in a streaming fashion. They support a number of
     additions from the standard SAX events, notably: type annotations
     on elements and attributes, as well as typed values resulting
     from XML Schema validation on top of the corresponding text
     content.
   - Jerome *)

(* Typed attributes *)

type typed_sax_xml_attribute =
    Sym.rattr_symbol            (* QNames are resolved *)
      * Datatypes.xdt_untyped
      * Datatypes._SimpleValue  (* Addition to the standard SAX events *)

type typed_sax_xml_attribute_forest =
    typed_sax_xml_attribute list

(* Typed elements *)

type typed_element_desc =
    Sym.relem_symbol                   (* QNames are resolved *)
      * typed_sax_xml_attribute_forest
      * Datatypes._SimpleValue         (* Addition to the standard SAX events *)
      * has_element_content

(* SAX events *)

type typed_sax_event =
  | TSAX_startDocument of sax_xml_decl option * sax_dtd_decl
  | TSAX_endDocument
  | TSAX_startElement of typed_element_desc
  | TSAX_endElement
  | TSAX_processingInstruction of pi_desc
  | TSAX_comment of comment_desc
  | TSAX_characters of text_desc
  | TSAX_namespace                             (* Addition to the standard SAX events *)
  | TSAX_attribute of typed_sax_xml_attribute  (* Addition to the standard SAX events *)
  | TSAX_atomicValue of Datatypes._AtomicValue (* Addition to the standard SAX events *)

(* Typed XML streams *)

(* Note:
     A typed XML stream is a Caml stream of typed SAX events. Please
     see the Stream Caml module for more on operations on streams.
   - Jerome *)

type typed_xml_stream = typed_sax_event Stream.t

