| 2 |
open Printf |
open Printf |
| 3 |
open Pxp_document |
open Pxp_document |
| 4 |
|
|
| 5 |
|
open Encodings |
| 6 |
|
open Encodings.Utf8.Pcre |
| 7 |
open Schema_common |
open Schema_common |
| 8 |
open Schema_types |
open Schema_types |
| 9 |
open Schema_validator |
open Schema_validator |
| 20 |
prerr_endline (sprintf "[%d] %s" line s); |
prerr_endline (sprintf "[%d] %s" line s); |
| 21 |
flush stderr) |
flush stderr) |
| 22 |
|
|
| 23 |
let regexp' s = Pcre.regexp ~flags:[`UTF8] s |
let space_RE = pcre_regexp " " |
| 24 |
let space_RE = regexp' " " |
let split s = pcre_split ~rex:space_RE s |
|
let split s = Pcre.split ~rex:space_RE s |
|
| 25 |
let hashtbl_deref tbl = |
let hashtbl_deref tbl = |
| 26 |
(* ASSUMPTION: no multiple bindings *) |
(* ASSUMPTION: no multiple bindings *) |
| 27 |
let tbl' = Hashtbl.create 1024 in |
let tbl' = Hashtbl.create 1024 in |
| 35 |
@raise Osv_validation_error if the same node is seen twice *) |
@raise Osv_validation_error if the same node is seen twice *) |
| 36 |
method see : pxp_node -> unit |
method see : pxp_node -> unit |
| 37 |
|
|
| 38 |
method resolve_att: ?fix_ns:bool -> string -> attribute_declaration |
method resolve_att: ?fix_ns:bool -> Utf8.t -> attribute_declaration |
| 39 |
method resolve_elt: |
method resolve_elt: |
| 40 |
?fix_ns:bool -> now:bool -> string -> element_declaration ref |
?fix_ns:bool -> now:bool -> Utf8.t -> element_declaration ref |
| 41 |
method resolve_typ: |
method resolve_typ: |
| 42 |
?fix_ns:bool -> now:bool -> string -> type_definition ref |
?fix_ns:bool -> now:bool -> Utf8.t -> type_definition ref |
| 43 |
method resolve_att_group: |
method resolve_att_group: |
| 44 |
?fix_ns:bool -> string -> attribute_group_definition |
?fix_ns:bool -> Utf8.t -> attribute_group_definition |
| 45 |
method resolve_model_group: ?fix_ns:bool -> string -> model_group_definition |
method resolve_model_group: ?fix_ns:bool -> Utf8.t -> model_group_definition |
| 46 |
method resolve_simple_typ: ?fix_ns:bool -> string -> simple_type_definition |
method resolve_simple_typ: ?fix_ns:bool -> Utf8.t -> simple_type_definition |
| 47 |
end |
end |
| 48 |
|
|
| 49 |
module OrderedNode = |
module OrderedNode = |
| 74 |
debug_print ~n "Schema_parser.parse_facet"; |
debug_print ~n "Schema_parser.parse_facet"; |
| 75 |
let validate_base_type = Schema_validator.validate_simple_type base in |
let validate_base_type = Schema_validator.validate_simple_type base in |
| 76 |
let validate_nonNegativeInteger = |
let validate_nonNegativeInteger = |
| 77 |
Schema_builtin.validate_builtin "xsd:nonNegativeInteger" |
Schema_builtin.validate_builtin |
| 78 |
|
(Schema_xml.add_xsd_prefix (Utf8.mk "nonNegativeInteger")) |
| 79 |
in |
in |
| 80 |
let facets = ref no_facets in |
let facets = ref no_facets in |
| 81 |
n#iter_nodes (fun n -> |
n#iter_nodes (fun n -> |
| 82 |
let fixed = (_has_attribute "fixed" n) && (_attribute "fixed" n = "true") in |
let fixed = |
| 83 |
|
(_has_attribute "fixed" n) && (_attribute "fixed" n = Utf8.mk "true") |
| 84 |
|
in |
| 85 |
match n#node_type with |
match n#node_type with |
| 86 |
| T_element "xsd:length" -> |
| T_element "xsd:length" -> |
| 87 |
let value = _attribute "value" n in |
let value = _attribute "value" n in |
| 96 |
let length = integer_of_value_t (validate_nonNegativeInteger value) in |
let length = integer_of_value_t (validate_nonNegativeInteger value) in |
| 97 |
facets := { !facets with maxLength = Some (length, fixed) } |
facets := { !facets with maxLength = Some (length, fixed) } |
| 98 |
| T_element "xsd:enumeration" -> |
| T_element "xsd:enumeration" -> |
| 99 |
let value = Value.string_latin1 (_attribute "value" n) in |
let value = Value.string_utf8 (_attribute "value" n) in |
| 100 |
let value = validate_base_type value in |
let value = validate_base_type value in |
| 101 |
let new_enumeration = |
let new_enumeration = |
| 102 |
(match !facets.enumeration with |
(match !facets.enumeration with |
| 105 |
in |
in |
| 106 |
facets := { !facets with enumeration = new_enumeration } |
facets := { !facets with enumeration = new_enumeration } |
| 107 |
| T_element "xsd:whiteSpace" -> |
| T_element "xsd:whiteSpace" -> |
| 108 |
let value = _attribute "value" n in |
let value = Utf8.get_str (_attribute "value" n) in |
| 109 |
facets := { !facets with whiteSpace = |
facets := { !facets with whiteSpace = |
| 110 |
((match value with |
((match value with |
| 111 |
| "collapse" -> `Collapse |
| "collapse" -> `Collapse |
| 114 |
| _ -> assert false), |
| _ -> assert false), |
| 115 |
fixed) } |
fixed) } |
| 116 |
| T_element "xsd:maxInclusive" -> |
| T_element "xsd:maxInclusive" -> |
| 117 |
let value = Value.string_latin1 (_attribute "value" n) in |
let value = Value.string_utf8 (_attribute "value" n) in |
| 118 |
facets := { !facets with |
facets := { !facets with |
| 119 |
maxInclusive = Some (validate_base_type value, fixed) } |
maxInclusive = Some (validate_base_type value, fixed) } |
| 120 |
| T_element "xsd:maxExclusive" -> |
| T_element "xsd:maxExclusive" -> |
| 121 |
let value = Value.string_latin1 (_attribute "value" n) in |
let value = Value.string_utf8 (_attribute "value" n) in |
| 122 |
facets := { !facets with |
facets := { !facets with |
| 123 |
maxExclusive = Some (validate_base_type value, fixed) } |
maxExclusive = Some (validate_base_type value, fixed) } |
| 124 |
| T_element "xsd:minInclusive" -> |
| T_element "xsd:minInclusive" -> |
| 125 |
let value = Value.string_latin1 (_attribute "value" n) in |
let value = Value.string_utf8 (_attribute "value" n) in |
| 126 |
facets := { !facets with |
facets := { !facets with |
| 127 |
minInclusive = Some (validate_base_type value, fixed) } |
minInclusive = Some (validate_base_type value, fixed) } |
| 128 |
| T_element "xsd:minExclusive" -> |
| T_element "xsd:minExclusive" -> |
| 129 |
let value = Value.string_latin1 (_attribute "value" n) in |
let value = Value.string_utf8 (_attribute "value" n) in |
| 130 |
facets := { !facets with |
facets := { !facets with |
| 131 |
minExclusive = Some (validate_base_type value, fixed) } |
minExclusive = Some (validate_base_type value, fixed) } |
| 132 |
| _ -> ()); |
| _ -> ()); |
| 199 |
let parse_att_value_constraint stype_def n = |
let parse_att_value_constraint stype_def n = |
| 200 |
debug_print ~n "Schema_parser.parse_att_value_constraint"; |
debug_print ~n "Schema_parser.parse_att_value_constraint"; |
| 201 |
if _has_attribute "default" n then |
if _has_attribute "default" n then |
| 202 |
let value = Value.string_latin1 (_attribute "default" n) in |
let value = Value.string_utf8 (_attribute "default" n) in |
| 203 |
let value = validate_simple_type stype_def value in |
let value = validate_simple_type stype_def value in |
| 204 |
Some (`Default value) |
Some (`Default value) |
| 205 |
else if _has_attribute "fixed" n then |
else if _has_attribute "fixed" n then |
| 206 |
let value = Value.string_latin1 (_attribute "fixed" n) in |
let value = Value.string_utf8 (_attribute "fixed" n) in |
| 207 |
let value = validate_simple_type stype_def value in |
let value = validate_simple_type stype_def value in |
| 208 |
Some (`Fixed value) |
Some (`Fixed value) |
| 209 |
else |
else |
| 216 |
match type_def with |
match type_def with |
| 217 |
| Simple st_def | Complex (_, _, _, _, _, CT_simple st_def) -> |
| Simple st_def | Complex (_, _, _, _, _, CT_simple st_def) -> |
| 218 |
validate_simple_type st_def |
validate_simple_type st_def |
| 219 |
| _ -> validate_simple_type (Primitive "xsd:string") |
| _ -> validate_simple_type (Primitive (Utf8.mk "xsd:string")) |
| 220 |
in |
in |
| 221 |
if _has_attribute "default" n then |
if _has_attribute "default" n then |
| 222 |
let value = Value.string_latin1 (_attribute "default" n) in |
let value = Value.string_utf8 (_attribute "default" n) in |
| 223 |
let value = validate_value value in |
let value = validate_value value in |
| 224 |
Some (`Default value) |
Some (`Default value) |
| 225 |
else if _has_attribute "fixed" n then |
else if _has_attribute "fixed" n then |
| 226 |
let value = Value.string_latin1 (_attribute "fixed" n) in |
let value = Value.string_utf8 (_attribute "fixed" n) in |
| 227 |
let value = validate_value value in |
let value = validate_value value in |
| 228 |
Some (`Fixed value) |
Some (`Fixed value) |
| 229 |
else |
else |
| 250 |
let parse_attribute_use (resolver: resolver) n = |
let parse_attribute_use (resolver: resolver) n = |
| 251 |
debug_print ~n "Schema_parser.parse_attribute_use"; |
debug_print ~n "Schema_parser.parse_attribute_use"; |
| 252 |
let required = |
let required = |
| 253 |
(_has_attribute "use" n) && (_attribute "use" n = "required") |
(_has_attribute "use" n) && (_attribute "use" n = Utf8.mk "required") |
| 254 |
in |
in |
| 255 |
let (name, type_def, value_constr) as att_decl = |
let (name, type_def, value_constr) as att_decl = |
| 256 |
if _has_attribute "ref" n then |
if _has_attribute "ref" n then |
| 295 |
|
|
| 296 |
let parse_min_max n = |
let parse_min_max n = |
| 297 |
((if _has_attribute "minOccurs" n then |
((if _has_attribute "minOccurs" n then |
| 298 |
Intervals.V.mk (_attribute "minOccurs" n) |
Intervals.V.mk (Utf8.get_str (_attribute "minOccurs" n)) |
| 299 |
else |
else |
| 300 |
Intervals.V.one), |
Intervals.V.one), |
| 301 |
(if _has_attribute "maxOccurs" n then |
(if _has_attribute "maxOccurs" n then |
| 302 |
match _attribute "maxOccurs" n with |
match Utf8.get_str (_attribute "maxOccurs" n) with |
| 303 |
| "unbounded" -> None |
| "unbounded" -> None |
| 304 |
| s -> Some (Intervals.V.mk s) |
| s -> Some (Intervals.V.mk s) |
| 305 |
else |
else |
| 370 |
let base = resolver#resolve_typ ~now:true (_attribute "base" derivation) in |
let base = resolver#resolve_typ ~now:true (_attribute "base" derivation) in |
| 371 |
let uses = parse_attribute_uses resolver derivation_type !base derivation in |
let uses = parse_attribute_uses resolver derivation_type !base derivation in |
| 372 |
let mixed = |
let mixed = |
| 373 |
(_has_attribute "mixed" content && (_attribute "mixed" content = "true")) |
(_has_attribute "mixed" content && |
| 374 |
|| (_has_attribute "mixed" n && (_attribute "mixed" n = "true")) |
(_attribute "mixed" content = Utf8.mk "true")) |
| 375 |
|
|| (_has_attribute "mixed" n && (_attribute "mixed" n = Utf8.mk "true")) |
| 376 |
in |
in |
| 377 |
let particle_node = find_particle derivation in |
let particle_node = find_particle derivation in |
| 378 |
let content_type = |
let content_type = |
| 402 |
else (* neither simpleContent nor complexContent *) |
else (* neither simpleContent nor complexContent *) |
| 403 |
let base = anyType in |
let base = anyType in |
| 404 |
let uses = parse_attribute_uses resolver `Restriction base n in |
let uses = parse_attribute_uses resolver `Restriction base n in |
| 405 |
let mixed = _has_attribute "mixed" n && (_attribute "mixed" n = "true") in |
let mixed = |
| 406 |
|
_has_attribute "mixed" n && (_attribute "mixed" n = Utf8.mk "true") |
| 407 |
|
in |
| 408 |
let content_type = |
let content_type = |
| 409 |
match find_particle n with |
match find_particle n with |
| 410 |
| None -> CT_empty |
| None -> CT_empty |
| 495 |
(** @param root schema document root node *) |
(** @param root schema document root node *) |
| 496 |
class lazy_resolver = |
class lazy_resolver = |
| 497 |
let fake_type_def = |
let fake_type_def = |
| 498 |
Complex (~-1, Some " FAKE TYP ", AnyType, `Restriction, [], CT_empty) |
Complex (~-1, Some (Utf8.mk " FAKE TYP "), AnyType, `Restriction, [], |
| 499 |
|
CT_empty) |
| 500 |
in |
in |
| 501 |
let fake_elt_decl = ~-2, " FAKE ELT ", ref fake_type_def, None in |
let fake_elt_decl = ~-2, Utf8.mk " FAKE ELT ", ref fake_type_def, None in |
| 502 |
let is_fake_type_def = (==) fake_type_def in |
let is_fake_type_def = (==) fake_type_def in |
| 503 |
let is_fake_elt_decl = (==) fake_elt_decl in |
let is_fake_elt_decl = (==) fake_elt_decl in |
| 504 |
let validation_error s = raise (XSD_validation_error s) in |
let validation_error s = raise (XSD_validation_error s) in |
| 505 |
let get_ns_prefix n = |
let get_ns_prefix n = |
| 506 |
match n#node_type with T_namespace p -> p | _ -> assert false |
match n#node_type with T_namespace p -> p | _ -> assert false |
| 507 |
in |
in |
| 508 |
|
let (^^) x y = Utf8.concat x y in |
| 509 |
fun root -> |
fun root -> |
| 510 |
object (self) |
object (self) |
| 511 |
|
|
| 512 |
val typs: (string, type_definition ref) Hashtbl.t = |
val typs: (Utf8.t, type_definition ref) Hashtbl.t = |
| 513 |
Hashtbl.create 17 |
Hashtbl.create 17 |
| 514 |
val attrs: (string, attribute_declaration) Hashtbl.t = |
val attrs: (Utf8.t, attribute_declaration) Hashtbl.t = |
| 515 |
Hashtbl.create 17 |
Hashtbl.create 17 |
| 516 |
val elts: (string, element_declaration ref) Hashtbl.t = |
val elts: (Utf8.t, element_declaration ref) Hashtbl.t = |
| 517 |
Hashtbl.create 17 |
Hashtbl.create 17 |
| 518 |
val attr_groups: (string, attribute_group_definition) Hashtbl.t = |
val attr_groups: (Utf8.t, attribute_group_definition) Hashtbl.t = |
| 519 |
Hashtbl.create 17 |
Hashtbl.create 17 |
| 520 |
val model_groups: (string, model_group_definition) Hashtbl.t = |
val model_groups: (Utf8.t, model_group_definition) Hashtbl.t = |
| 521 |
Hashtbl.create 17 |
Hashtbl.create 17 |
| 522 |
|
|
| 523 |
val mutable seen_nodes = NodeSet.empty |
val mutable seen_nodes = NodeSet.empty |
| 533 |
let type_def = Simple st_def in |
let type_def = Simple st_def in |
| 534 |
let name = name_of_type_definition type_def in |
let name = name_of_type_definition type_def in |
| 535 |
Hashtbl.replace typs name (ref type_def)); |
Hashtbl.replace typs name (ref type_def)); |
| 536 |
Hashtbl.replace typs "xsd:anyType" (ref AnyType); |
Hashtbl.replace typs (Utf8.mk "xsd:anyType") (ref AnyType); |
| 537 |
List.iter (* fill namespace manager *) |
List.iter (* fill namespace manager *) |
| 538 |
(fun (p, ns) -> namespace_manager#add_namespace p ns) |
(fun (p, ns) -> |
| 539 |
|
namespace_manager#add_namespace (Utf8.get_str p) (Utf8.get_str ns)) |
| 540 |
Schema_xml.schema_ns_prefixes; |
Schema_xml.schema_ns_prefixes; |
| 541 |
List.iter |
List.iter |
| 542 |
(fun n -> |
(fun n -> |
| 551 |
let ns = _attribute "targetNamespace" root in |
let ns = _attribute "targetNamespace" root in |
| 552 |
targetNamespace <- Some ns; |
targetNamespace <- Some ns; |
| 553 |
targetNamespace_prefix <- |
targetNamespace_prefix <- |
| 554 |
namespace_manager#lookup_or_add_namespace targetNamespace_prefix ns |
namespace_manager#lookup_or_add_namespace |
| 555 |
|
targetNamespace_prefix (Utf8.get_str ns) |
| 556 |
end; |
end; |
| 557 |
|
|
| 558 |
(** schemas namespaces handling *) |
(** schemas namespaces handling *) |
| 560 |
method targetNamespace = |
method targetNamespace = |
| 561 |
match targetNamespace with |
match targetNamespace with |
| 562 |
| None -> Ns.empty |
| None -> Ns.empty |
| 563 |
| Some s -> Ns.mk_ascii s |
| Some s -> Ns.mk s |
| 564 |
|
|
| 565 |
(* qualify names of entities before registering them with defined |
(* qualify names of entities before registering them with defined |
| 566 |
* targetNamespace, if any *) |
* targetNamespace, if any *) |
| 567 |
method private qualify_name s = |
method private qualify_name name = |
| 568 |
match targetNamespace with |
match targetNamespace with |
| 569 |
| None -> s |
| None -> name |
| 570 |
| Some _ -> sprintf "%s:%s" targetNamespace_prefix s |
| Some _ -> (Utf8.mk (targetNamespace_prefix ^ ":")) ^^ name |
| 571 |
|
|
| 572 |
(* resolve user references using our namespace manager *) |
(* resolve user references using our namespace manager *) |
| 573 |
method private fix_namespace s = |
method private fix_namespace s = |
| 574 |
match namespace_split s with |
match Ns.split_qname s with |
| 575 |
| "", base -> |
| "", base -> |
| 576 |
(match targetNamespace with |
(match targetNamespace with |
| 577 |
| None -> base |
| None -> base |
| 578 |
| Some _ -> targetNamespace_prefix ^ ":" ^ base) |
| Some _ -> (Utf8.mk targetNamespace_prefix) ^^ (Utf8.mk ":") ^^ base) |
| 579 |
| prefix, base -> |
| prefix, base -> |
| 580 |
(try |
(try |
| 581 |
let orig_uri = Hashtbl.find orig_ns_prefixes prefix in |
let orig_uri = Hashtbl.find orig_ns_prefixes prefix in |
| 582 |
let new_prefix = namespace_manager#get_normprefix orig_uri in |
let new_prefix = namespace_manager#get_normprefix orig_uri in |
| 583 |
new_prefix ^ ":" ^ base |
(Utf8.mk new_prefix) ^^ (Utf8.mk ":") ^^ base |
| 584 |
with Not_found -> validation_error ("Can't resolve: " ^ s)) |
with Not_found -> |
| 585 |
|
validation_error ("Can't resolve: " ^ Utf8.get_str s)) |
| 586 |
|
|
| 587 |
(** seen nodes accounting *) |
(** seen nodes accounting *) |
| 588 |
|
|
| 594 |
seen_nodes <- NodeSet.add n seen_nodes |
seen_nodes <- NodeSet.add n seen_nodes |
| 595 |
|
|
| 596 |
method private find_global_component tag_pred name = |
method private find_global_component tag_pred name = |
| 597 |
let basename = snd (namespace_split name) in |
let basename = snd (Ns.split_qname name) in |
| 598 |
find (fun n -> match n#node_type with |
find (fun n -> match n#node_type with |
| 599 |
| T_element tag when tag_pred tag -> |
| T_element tag when tag_pred tag -> |
| 600 |
(_has_attribute "name" n) && (_attribute "name" n = basename) |
(_has_attribute "name" n) && (_attribute "name" n = basename) |
| 607 |
let name = self#qualify_name name in |
let name = self#qualify_name name in |
| 608 |
if (Hashtbl.mem typs name) && |
if (Hashtbl.mem typs name) && |
| 609 |
(not (is_fake_type_def !(Hashtbl.find typs name))) then |
(not (is_fake_type_def !(Hashtbl.find typs name))) then |
| 610 |
validation_error ("Redefinition of type: " ^ name); |
validation_error ("Redefinition of type: " ^ Utf8.get_str name); |
| 611 |
debug_print (sprintf "Osv_parser: registering TYPE %s" name); |
debug_print (sprintf "Osv_parser: registering TYPE %s" |
| 612 |
|
(Utf8.get_str name)); |
| 613 |
let type_def_ref = self#resolve_typ ~fix_ns:false ~now:false name in |
let type_def_ref = self#resolve_typ ~fix_ns:false ~now:false name in |
| 614 |
type_def_ref := def |
type_def_ref := def |
| 615 |
|
|
| 618 |
let name = self#qualify_name name in |
let name = self#qualify_name name in |
| 619 |
if (Hashtbl.mem elts name) && |
if (Hashtbl.mem elts name) && |
| 620 |
(not (is_fake_elt_decl !(Hashtbl.find elts name))) then |
(not (is_fake_elt_decl !(Hashtbl.find elts name))) then |
| 621 |
validation_error ("Redefinition of element: " ^ name); |
validation_error ("Redefinition of element: " ^ Utf8.get_str name); |
| 622 |
debug_print (sprintf "Osv_parser: registering ELEMENT %s" name); |
debug_print (sprintf "Osv_parser: registering ELEMENT %s" |
| 623 |
|
(Utf8.get_str name)); |
| 624 |
let elt_decl_ref = self#resolve_elt ~fix_ns:false ~now:false name in |
let elt_decl_ref = self#resolve_elt ~fix_ns:false ~now:false name in |
| 625 |
elt_decl_ref := decl |
elt_decl_ref := decl |
| 626 |
|
|
| 628 |
debug_print "lazy_resolver.register_att"; |
debug_print "lazy_resolver.register_att"; |
| 629 |
let name = self#qualify_name name in |
let name = self#qualify_name name in |
| 630 |
if Hashtbl.mem attrs name then |
if Hashtbl.mem attrs name then |
| 631 |
validation_error ("Redefinition of attribute: " ^ name); |
validation_error ("Redefinition of attribute: " ^ Utf8.get_str name); |
| 632 |
debug_print (sprintf "Osv_parser: registering ATTRIBUTE %s" name); |
debug_print (sprintf "Osv_parser: registering ATTRIBUTE %s" |
| 633 |
|
(Utf8.get_str name)); |
| 634 |
Hashtbl.replace attrs name decl |
Hashtbl.replace attrs name decl |
| 635 |
|
|
| 636 |
method register_att_group name def = |
method register_att_group name def = |
| 637 |
debug_print "lazy_resolver.register_att_group"; |
debug_print "lazy_resolver.register_att_group"; |
| 638 |
let name = self#qualify_name name in |
let name = self#qualify_name name in |
| 639 |
if Hashtbl.mem attr_groups name then |
if Hashtbl.mem attr_groups name then |
| 640 |
validation_error ("Redefinition of attribute group: " ^ name); |
validation_error ("Redefinition of attribute group: " ^ |
| 641 |
debug_print (sprintf "Osv_parser: registering ATTRIBUTE GROUP %s" name); |
Utf8.get_str name); |
| 642 |
|
debug_print (sprintf "Osv_parser: registering ATTRIBUTE GROUP %s" |
| 643 |
|
(Utf8.get_str name)); |
| 644 |
Hashtbl.replace attr_groups name def |
Hashtbl.replace attr_groups name def |
| 645 |
|
|
| 646 |
method register_model_group name def = |
method register_model_group name def = |
| 647 |
debug_print "lazy_resolver.register_model_group"; |
debug_print "lazy_resolver.register_model_group"; |
| 648 |
let name = self#qualify_name name in |
let name = self#qualify_name name in |
| 649 |
if Hashtbl.mem model_groups name then |
if Hashtbl.mem model_groups name then |
| 650 |
validation_error ("Redefinition of model group: " ^ name); |
validation_error ("Redefinition of model group: " ^ Utf8.get_str name); |
| 651 |
debug_print (sprintf "Osv_parser: registering MODEL GROUP %s" name); |
debug_print (sprintf "Osv_parser: registering MODEL GROUP %s" |
| 652 |
|
(Utf8.get_str name)); |
| 653 |
Hashtbl.replace model_groups name def |
Hashtbl.replace model_groups name def |
| 654 |
|
|
| 655 |
(** entities lookup *) |
(** entities lookup *) |
| 669 |
(tag = "xsd:simpleType") || (tag = "xsd:complexType")) |
(tag = "xsd:simpleType") || (tag = "xsd:complexType")) |
| 670 |
name |
name |
| 671 |
with Not_found -> |
with Not_found -> |
| 672 |
validation_error ("Can't find definition of type: " ^ name) |
validation_error ("Can't find definition of type: " ^ |
| 673 |
|
Utf8.get_str name) |
| 674 |
in |
in |
| 675 |
if _tag_name type_node = "xsd:simpleType" then |
if _tag_name type_node = Utf8.mk "xsd:simpleType" then |
| 676 |
Simple (parse_simple_type (self :> resolver) type_node) |
Simple (parse_simple_type (self :> resolver) type_node) |
| 677 |
else (* _tag_name type_node = "xsd:complexType" *) |
else (* _tag_name type_node = "xsd:complexType" *) |
| 678 |
Complex (parse_complex_type (self :> resolver) type_node) |
Complex (parse_complex_type (self :> resolver) type_node) |
| 685 |
|
|
| 686 |
method resolve_simple_typ ?(fix_ns = true) name = |
method resolve_simple_typ ?(fix_ns = true) name = |
| 687 |
match !(self#resolve_typ ~fix_ns ~now:true name) with |
match !(self#resolve_typ ~fix_ns ~now:true name) with |
| 688 |
| AnyType -> Primitive "xsd:anySimpleType" |
| AnyType -> Primitive (Utf8.mk "xsd:anySimpleType") |
| 689 |
| Simple st -> st |
| Simple st -> st |
| 690 |
| Complex _ -> assert false |
| Complex _ -> assert false |
| 691 |
|
|
| 701 |
try |
try |
| 702 |
self#find_global_component ((=) "xsd:element") name |
self#find_global_component ((=) "xsd:element") name |
| 703 |
with Not_found -> |
with Not_found -> |
| 704 |
validation_error ("Can't find declaration of element: " ^ name) |
validation_error ("Can't find declaration of element: " ^ |
| 705 |
|
Utf8.get_str name) |
| 706 |
in |
in |
| 707 |
parse_elt_decl (self :> resolver) elt_node |
parse_elt_decl (self :> resolver) elt_node |
| 708 |
else (* resolve later: return a fake element declaration *) |
else (* resolve later: return a fake element declaration *) |
| 722 |
try |
try |
| 723 |
self#find_global_component ((=) "xsd:attribute") name |
self#find_global_component ((=) "xsd:attribute") name |
| 724 |
with Not_found -> |
with Not_found -> |
| 725 |
validation_error ("Can't find declaration of attribute: " ^ name) |
validation_error ("Can't find declaration of attribute: " ^ |
| 726 |
|
Utf8.get_str name) |
| 727 |
in |
in |
| 728 |
let att_decl = parse_att_decl (self :> resolver) node in |
let att_decl = parse_att_decl (self :> resolver) node in |
| 729 |
Hashtbl.replace attrs name att_decl; |
Hashtbl.replace attrs name att_decl; |
| 740 |
self#find_global_component ((=) "xsd:attributeGroup") name |
self#find_global_component ((=) "xsd:attributeGroup") name |
| 741 |
with Not_found -> |
with Not_found -> |
| 742 |
validation_error |
validation_error |
| 743 |
("Can't find definition of attribute group: " ^ name) |
("Can't find definition of attribute group: " ^ Utf8.get_str name) |
| 744 |
in |
in |
| 745 |
let att_group_decl = parse_att_group (self :> resolver) node in |
let att_group_decl = parse_att_group (self :> resolver) node in |
| 746 |
Hashtbl.replace attr_groups name att_group_decl; |
Hashtbl.replace attr_groups name att_group_decl; |
| 757 |
self#find_global_component ((=) "xsd:group") name |
self#find_global_component ((=) "xsd:group") name |
| 758 |
with Not_found -> |
with Not_found -> |
| 759 |
validation_error |
validation_error |
| 760 |
("Can't find definition of model group: " ^ name) |
("Can't find definition of model group: " ^ Utf8.get_str name) |
| 761 |
in |
in |
| 762 |
let model_group = parse_model_group_def (self :> resolver) node in |
let model_group = parse_model_group_def (self :> resolver) node in |
| 763 |
Hashtbl.replace model_groups name model_group; |
Hashtbl.replace model_groups name model_group; |