schema_types.mli 3.88 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
*)

(**
  Glossary:
10
11
12
  XSD   XML Schema Document
  PSV   Post Schema Validation
  PSVI  Post Schema Validation Infoset
13
*)
14

15
16
open Encodings

17
18
(** {2 XSD representation} *)

19
20
21
22
type derivation_type = [ `Extension | `Restriction ]
type white_space_handling = [ `Preserve | `Replace | `Collapse ]

type facets = {
23
24
25
  length: (int * bool) option;      (* length, fixed *)
  minLength: (int * bool) option;   (* length, fixed *)
  maxLength: (int * bool) option;   (* length, fixed *)
26
(*   pattern: Schema_regexp.regexp list;           (* list of ANDed patterns *) *)
27
  enumeration: value_ref list option;
28
  whiteSpace: white_space_handling * bool;           (* handling, fixed *)
29
30
31
32
  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 *)
33
34
35
36
37
38
(*
  totalDigits: (xs_positiveInteger * bool) option;     (* digits, fixed *)
  fractionDigits: (xs_nonNegativeInteger * bool) option;  (* digits, fixed *)
*)
}

39
40
41
and value_ref = Value.t Lazy.t
and value_constraint = [ `Fixed of value_ref | `Default of value_ref ]

42
and type_ref = type_definition Lazy.t
43
44

and simple_type_definition =
45
  | Primitive of Ns.qname
46
  | Derived of
47
      Ns.qname option * (* name *)
48
49
50
	variety *
	facets *
	type_ref (* base *)
51
52

and variety =
53
54
55
56
57
  | Atomic of type_ref (* a Primitive _ *)
  | List of type_ref    
      (* Variety (simple_type_definition) = Atomic || Union (of atomic) *)
  | Union of type_ref list
  | Restrict
58

59
and attribute_declaration =
60
    { attr_name : Ns.qname;
61
      attr_typdef : type_ref;
62
      attr_cstr : value_constraint option }
63

64
and attribute_use =
65
66
67
    { attr_required : bool;
      attr_decl : attribute_declaration;
      attr_use_cstr : value_constraint option }
68

69
and term =
70
  | Elt of element_declaration
71
  | Model of model_group
72
73

and model_group =
74
75
76
77
78
79
  | All of particle list
  | Choice of particle list
  | Sequence of particle list

and content_type =
  | CT_empty
80
  | CT_simple of type_ref
81
  | CT_model of particle * bool        (* mixed *)
82
83

and particle =
84
85
86
87
88
    { part_min: int;
      part_max: int option;  (* None = unbounded *)
      part_term: term;
      part_first: Ns.qname list;
      part_nullable: bool }
89
90

and element_declaration =
91
    { elt_uid: int;
92
      elt_name: Ns.qname;
93
      elt_typdef: type_ref;
94
      elt_cstr: value_constraint option }
95

96
and complex_type_definition =
97
    { ct_uid: int;
98
      ct_name: Ns.qname option;
99
100
101
102
      ct_typdef: type_definition;
      ct_deriv: derivation_type;
      ct_attrs: attribute_use list;
      ct_content: content_type }
103

104
105
106
107
and type_definition =
  | AnyType
  | Simple of simple_type_definition
  | Complex of complex_type_definition
108

109
type model_group_definition =
110
    { mg_name : Ns.qname;
111
      mg_def : model_group }
112

113
type attribute_group_definition =
114
    { ag_name : Ns.qname;
115
      ag_def : attribute_use list }
116
117

type schema = {
118
  targetNamespace: Ns.t;
119
120
121
122
123
124
  types: type_definition list;
  attributes: attribute_declaration list;
  elements: element_declaration list;
  attribute_groups: attribute_group_definition list;
  model_groups: model_group_definition list;
}
125

126
127
128
129
130
131
132
133
(** {2 Events} see Schema_events module *)

type event =
  | E_start_tag of Ns.qname
  | E_end_tag of Ns.qname
  | E_attribute of Ns.qname * Encodings.Utf8.t  (* qualified name, value *)
  | E_char_data of Encodings.Utf8.t

134
135
136
137
138
139
140
141
142
143
144
145
146
(** {2 Misc} *)

  (* kind of a schema component *)
type component_kind =
  [ `Type | `Element | `Attribute | `Attribute_group | `Model_group ] option

type component =
  | Type of type_definition
  | Element of element_declaration
  | Attribute of attribute_declaration
  | Attribute_group of attribute_group_definition
  | Model_group of model_group_definition