82
85
(* prefix = "": make sure that such a prefix is never added *)
84
87
method get_primary_uri normprefix =
85
Hashtbl.find primary_uri_of_prefix normprefix
89
Hashtbl.find primary_uri_of_prefix normprefix
92
raise(Namespace_prefix_not_managed normprefix)
87
94
method get_uri_list normprefix =
88
95
Hashtbl.find_all uri_of_prefix normprefix
90
97
method get_normprefix uri =
91
Hashtbl.find prefix_of_uri uri
99
Hashtbl.find prefix_of_uri uri
102
raise(Namespace_not_managed uri)
93
104
method iter_namespaces f =
95
106
(fun p uri -> f p)
96
107
primary_uri_of_prefix
109
method as_declaration =
112
(fun p uri -> l := (p, uri) :: !l)
113
primary_uri_of_prefix;
101
class dtd the_warner init_encoding =
120
let create_namespace_manager () = new namespace_manager;;
123
class type namespace_scope =
125
method namespace_manager : namespace_manager
126
method parent_scope : namespace_scope option
127
method declaration : (string * string) list
128
method effective_declaration : (string * string) list
129
method display_prefix_of_uri : string -> string
130
method display_prefix_of_normprefix : string -> string
131
method uri_of_display_prefix : string -> string
132
method normprefix_of_display_prefix : string -> string
138
module StrSet = Set.Make(String);;
140
class namespace_scope_impl mng parent_opt decl : namespace_scope =
142
method namespace_manager = mng
143
method parent_scope = parent_opt
144
method declaration = decl
146
method effective_declaration =
147
let rec collect visible d s =
150
if StrSet.mem "" visible then
151
collect visible d' s (* no effect *)
153
collect (StrSet.add "" visible) d' s (* hide inner default *)
155
if StrSet.mem dp visible then
158
(dp, uri) :: collect (StrSet.add dp visible) d' s
160
( match s # parent_scope with
162
collect visible s'#declaration s'
167
collect StrSet.empty self#declaration (self : #namespace_scope :> namespace_scope)
169
method display_prefix_of_uri uri =
171
fst(List.find (fun (p,u) -> u = uri) decl)
174
( match parent_opt with
175
Some pa -> pa # display_prefix_of_uri uri
176
| None -> raise(Namespace_not_in_scope uri)
179
method display_prefix_of_normprefix np =
180
let uris = mng # get_uri_list np in
181
if uris = [] then raise(Namespace_prefix_not_managed np);
183
fst(List.find (fun (p,u) -> List.mem u uris) decl)
186
( match parent_opt with
187
Some pa -> pa # display_prefix_of_normprefix np
188
| None -> raise(Namespace_not_in_scope
189
(List.hd(List.rev uris)))
192
method uri_of_display_prefix dp =
197
( match parent_opt with
198
Some pa -> pa # uri_of_display_prefix dp
199
| None -> raise Not_found
202
method normprefix_of_display_prefix dp =
203
let uri = self # uri_of_display_prefix dp in
204
mng # get_normprefix uri
210
let create_namespace_scope ?parent ?(decl = []) mng =
211
new namespace_scope_impl mng parent decl ;;
214
class dtd ?swarner the_warner init_encoding =
103
216
val mutable root = (None : string option)
104
217
val mutable id = (None : dtd_id option)
105
218
val mutable mng = (None : namespace_manager option)
107
220
val warner = (the_warner : collect_warnings)
221
val swarner = (swarner : symbolic_warnings option)
108
222
val encoding = init_encoding
109
val lexerset = Pxp_lexers.get_lexer_set init_encoding
223
val lfactory = Pxp_lexers.get_lexer_factory init_encoding
111
225
val elements = (Str_hashtbl.create 100 : dtd_element Str_hashtbl.t)
112
226
val gen_entities = (Str_hashtbl.create 100 : (entity * bool) Str_hashtbl.t)
1163
1287
let replacement_text ent = fst(ent # replacement_text)
1164
1288
let get_xid ent =
1165
1289
try Some(ent # ext_id) with Not_found -> None
1290
let get_resolver_id ent =
1291
try Some(ent # resolver_id) with Not_found -> None
1166
1292
let get_notation ent =
1167
1293
if ent # is_ndata then Some (ent # notation) else None
1168
1294
let create_internal_entity ~name ~value dtd =
1169
new internal_entity dtd name (dtd # warner) value false false
1295
new internal_entity dtd name (dtd # swarner) (dtd # warner) value
1296
false false (dtd # encoding)
1171
1297
let create_ndata_entity ~name ~xid ~notation dtd =
1172
1298
new ndata_entity name xid notation dtd#encoding
1173
let create_external_entity ?(doc_entity = false) ~name ~xid ~resolver dtd =
1299
let create_external_entity ?(doc_entity = false) ?system_base
1300
~name ~xid ~resolver dtd =
1174
1301
if doc_entity then
1175
new document_entity resolver dtd name dtd#warner xid dtd#encoding
1302
new document_entity resolver dtd name dtd#swarner dtd#warner xid
1303
system_base dtd#encoding
1177
new external_entity resolver dtd name dtd#warner xid false dtd#encoding
1305
new external_entity resolver dtd name dtd#swarner dtd#warner xid
1306
system_base false dtd#encoding
1178
1307
let from_external_source ?doc_entity ~name dtd src =
1180
1309
ExtID(xid,resolver) ->
1181
1310
create_external_entity ?doc_entity ~name ~xid ~resolver dtd
1311
| XExtID(xid,system_base,resolver) ->
1312
create_external_entity ?doc_entity ?system_base
1313
~name ~xid ~resolver dtd
1182
1314
| Entity(make,resolver) ->
1183
1315
make dtd (* resolver ignored *)
1317
let entity_id ent = (ent :> < >)
1319
class fake = object end
1321
let create_entity_id () = new fake
1187
(* ======================================================================
1190
* $Log: pxp_dtd.ml,v $
1191
* Revision 1.21 2002/03/10 23:39:28 gerd
1192
* Extended the Entity module
1194
* Revision 1.20 2001/12/03 23:45:55 gerd
1195
* new method [write_ref]
1197
* Revision 1.19 2001/07/02 23:21:40 gerd
1198
* Added the Entity module.
1200
* Revision 1.18 2001/06/29 13:57:30 gerd
1201
* Weakened the xml:space check.
1203
* Revision 1.17 2001/06/08 01:15:46 gerd
1204
* Moved namespace_manager from Pxp_document to Pxp_dtd. This
1205
* makes it possible that the DTD can recognize the processing instructions
1206
* <?pxp:dtd namespace prefix="..." uri="..."?>, and add the namespace
1207
* declaration to the manager.
1209
* Revision 1.16 2001/06/07 22:48:38 gerd
1210
* Improvement: 'write' writes sorted attributes. This makes
1211
* many regression tests simpler.
1213
* Revision 1.15 2001/04/22 14:14:41 gerd
1214
* Updated to support private IDs.
1216
* Revision 1.14 2000/10/01 19:47:19 gerd
1217
* Using Str_hashtbl instead of Hashtbl.
1219
* Revision 1.13 2000/09/22 22:54:30 gerd
1220
* Optimized the attribute checker (internal_init of element
1221
* nodes). The validation_record has now more fields to support
1224
* Revision 1.12 2000/09/16 22:40:50 gerd
1225
* Bug processing processing instructions: Method
1226
* pinstr_names returned wrong results; method write wrote
1227
* the wrong instructions.
1229
* Revision 1.11 2000/09/09 16:41:32 gerd
1230
* New type validation_record.
1232
* Revision 1.10 2000/08/18 21:18:45 gerd
1233
* Updated wrong comments for methods par_entity and gen_entity.
1234
* These can raise WF_error and not Validation_error, and this is the
1235
* correct behaviour.
1237
* Revision 1.9 2000/07/25 00:30:01 gerd
1238
* Added support for pxp:dtd PI options.
1240
* Revision 1.8 2000/07/23 02:16:34 gerd
1243
* Revision 1.7 2000/07/16 17:50:01 gerd
1246
* Revision 1.6 2000/07/16 16:34:41 gerd
1247
* New method 'write', the successor of 'write_compact_as_latin1'.
1249
* Revision 1.5 2000/07/14 13:56:48 gerd
1250
* Added methods id_attribute_name and idref_attribute_names.
1252
* Revision 1.4 2000/07/09 00:13:37 gerd
1253
* Added methods gen_entity_names, par_entity_names.
1255
* Revision 1.3 2000/07/04 22:10:55 gerd
1256
* Update: collect_warnings -> drop_warnings.
1257
* Update: Case ext_id = Anonymous.
1259
* Revision 1.2 2000/06/14 22:19:06 gerd
1260
* Added checks such that it is impossible to mix encodings.
1262
* Revision 1.1 2000/05/29 23:48:38 gerd
1263
* Changed module names:
1264
* Markup_aux into Pxp_aux
1265
* Markup_codewriter into Pxp_codewriter
1266
* Markup_document into Pxp_document
1267
* Markup_dtd into Pxp_dtd
1268
* Markup_entity into Pxp_entity
1269
* Markup_lexer_types into Pxp_lexer_types
1270
* Markup_reader into Pxp_reader
1271
* Markup_types into Pxp_types
1272
* Markup_yacc into Pxp_yacc
1273
* See directory "compatibility" for (almost) compatible wrappers emulating
1274
* Markup_document, Markup_dtd, Markup_reader, Markup_types, and Markup_yacc.
1276
* ======================================================================
1278
* Revision 1.18 2000/05/28 17:24:55 gerd
1281
* Revision 1.17 2000/05/27 19:21:25 gerd
1282
* Implemented the changes of rev. 1.10 of markup_dtd.mli.
1284
* Revision 1.16 2000/05/20 20:31:40 gerd
1285
* Big change: Added support for various encodings of the
1286
* internal representation.
1288
* Revision 1.15 2000/05/14 21:50:07 gerd
1289
* Updated: change in internal_entity.
1291
* Revision 1.14 2000/05/06 23:08:46 gerd
1292
* It is possible to allow undeclared attributes.
1294
* Revision 1.13 2000/05/01 20:42:46 gerd
1295
* New method write_compact_as_latin1.
1297
* Revision 1.12 2000/05/01 15:16:57 gerd
1298
* The errors "undeclared parameter/general entities" are
1299
* well-formedness errors, not validation errors.
1301
* Revision 1.11 2000/03/11 22:58:15 gerd
1302
* Updated to support Markup_codewriter.
1304
* Revision 1.10 2000/01/20 20:53:47 gerd
1305
* Changed such that it runs with Markup_entity's new interface.
1307
* Revision 1.9 1999/11/09 22:15:41 gerd
1308
* Added method "arbitrary_allowed".
1310
* Revision 1.8 1999/09/01 22:52:22 gerd
1311
* If 'allow_arbitrary' is in effect, no validation happens anymore.
1313
* Revision 1.7 1999/09/01 16:21:24 gerd
1314
* Added several warnings.
1315
* The attribute type of "xml:space" is now strictly checked.
1317
* Revision 1.6 1999/08/15 20:34:21 gerd
1318
* Improved error messages.
1319
* Bugfix: It is no longer allowed to create processing instructions
1320
* with target "xml".
1322
* Revision 1.5 1999/08/15 02:20:16 gerd
1323
* New feature: a DTD can allow arbitrary elements.
1325
* Revision 1.4 1999/08/15 00:21:39 gerd
1326
* Comments have been updated.
1328
* Revision 1.3 1999/08/14 22:12:52 gerd
1329
* Several functions have now a "warner" as argument which is
1330
* an object with a "warn" method. This is used to warn about characters
1331
* that cannot be represented in the Latin 1 alphabet.
1332
* Bugfix: if two general entities with the same name are definied,
1333
* the first counts, not the second.
1335
* Revision 1.2 1999/08/11 14:56:35 gerd
1336
* Declaration of the predfined entities {lt,gt,amp,quot,apos}
1337
* is no longer forbidden; but the original definition cannot be overriddden.
1338
* TODO: If these entities are redeclared with problematic values,
1339
* the user should be warned.
1341
* Revision 1.1 1999/08/10 00:35:51 gerd