schema_types.ml 3.57 KB
Newer Older
1 2
(** 
  Internal representation of an XML Schema.
3

4 5
  Note: this module comes in .mli part only, hence no value and/or
  exceptions are available here. See Schema_common.
6 7 8 9 10 11 12 13
*)

open Encodings

type derivation_type = [ `Extension | `Restriction ]
type white_space_handling = [ `Preserve | `Replace | `Collapse ]

type facets = {
14 15 16
  length: (int * bool) option;      (* length, fixed *)
  minLength: (int * bool) option;   (* length, fixed *)
  maxLength: (int * bool) option;   (* length, fixed *)
17
(*   pattern: Schema_regexp.regexp list;           (* list of ANDed patterns *) *)
18
  enumeration: value_ref list option;
19
  whiteSpace: white_space_handling * bool;           (* handling, fixed *)
20 21 22 23
  maxInclusive: (value_ref * bool) option;        (* max, fixed *)
  maxExclusive: (value_ref * bool) option;        (* max, fixed *)
  minInclusive: (value_ref * bool) option;        (* min, fixed *)
  minExclusive: (value_ref * bool) option;        (* min, fixed *)
24 25 26 27 28 29
(*
  totalDigits: (xs_positiveInteger * bool) option;     (* digits, fixed *)
  fractionDigits: (xs_nonNegativeInteger * bool) option;  (* digits, fixed *)
*)
}

30
and value_ref = Value.t
31 32
and value_constraint = 
    [ `Fixed of Utf8.t * Value.t | `Default of Utf8.t * Value.t ]
33

34
and type_ref = type_definition Lazy.t
35

36
and simple_type_definition = {
37
  st_name: Ns.QName.t option;
38 39 40 41
  st_variety: variety;
  st_facets: facets;
  st_base: simple_type_definition option;
}
42 43

and variety =
44 45 46
  | Atomic of simple_type_definition
  | List of simple_type_definition
  | Union of simple_type_definition list
47

48
and attribute_declaration =
49
    { attr_name : Ns.Label.t;
50
      attr_typdef : simple_type_definition;
51
      attr_cstr : value_constraint option }
52

53
and attribute_use =
54 55 56
    { attr_required : bool;
      attr_decl : attribute_declaration;
      attr_use_cstr : value_constraint option }
57

58
and term =
59
  | Elt of element_declaration
60
  | Model of model_group
61
  | Wildcard of wildcard
62 63 64 65 66 67 68 69

and model_group =
  | All of particle list
  | Choice of particle list
  | Sequence of particle list

and content_type =
  | CT_empty
70
  | CT_simple of simple_type_definition
71
  | CT_model of particle * bool        (* mixed *)
72 73

and particle =
74 75 76
    { part_min: int;
      part_max: int option;  (* None = unbounded *)
      part_term: term;
77
      part_first: Atoms.t;
78
      part_nullable: bool }
79 80

and element_declaration =
81
    { elt_name: Atoms.V.t;
82
      elt_typdef: type_ref;
83
      elt_cstr: value_constraint option;
84 85
      elt_nillable: bool;
    }
86 87

and complex_type_definition =
88
    { ct_uid: int;
89
      ct_name: Ns.QName.t option;
90 91
      ct_typdef: type_definition;
      ct_deriv: derivation_type;
92 93 94 95 96 97
      ct_attrs: attribute_uses;
      ct_content: content_type;
    }

and attribute_uses = attribute_use list * bool  
  (* true = allow other attribs *)
98 99 100 101 102 103

and type_definition =
  | AnyType
  | Simple of simple_type_definition
  | Complex of complex_type_definition

104 105
and wildcard_constraint =
  | WAny
106 107
  | WNot of Ns.Uri.t
  | WOne of Ns.Uri.t list
108 109 110 111 112 113 114

and wildcard = {
  wild_cstr: wildcard_constraint;
  wild_process: [`Lax | `Skip | `Strict];
  wild_first: Atoms.t;
}

115
type model_group_definition =
116
    { mg_name : Ns.QName.t;
117
      mg_def : model_group }
118 119

type attribute_group_definition =
120
    { ag_name : Ns.QName.t;
121
      ag_def : attribute_uses }
122 123

type schema = {
124
  targetNamespace: Ns.Uri.t;
125 126 127 128 129 130 131 132
  types: type_definition list;
  attributes: attribute_declaration list;
  elements: element_declaration list;
  attribute_groups: attribute_group_definition list;
  model_groups: model_group_definition list;
}

type event =
133
  | E_start_tag of Atoms.V.t
134
  | E_end_tag
135
  | E_attribute of Ns.Label.t * Utf8.t
136
  | E_char_data of Utf8.t