Commit ad00799c authored by Pietro Abate's avatar Pietro Abate

[r2003-06-15 21:47:15 by cvscast] different exit codes depending on the validation outcome zack

Original author: cvscast
Date: 2003-06-15 21:47:15+00:00
parent 97950249
(* XML Schema validator *)
(*
XML Schema validator
Usage: validate <schema_document> [ <instance_document> ... ]
Exit codes:
0 validation ok
1 wrong invocation
2 error validating schema document
3 error validating instance document
*)
open Printf
open Pxp_document
open Schema_types
let die_usage () =
prerr_endline
"Usage: validate <schema_document> [ <instance_document> ... ]";
exit 1
exception Usage
let schema_file = try Sys.argv.(1) with Invalid_argument _ -> die_usage ()
let debug = true
let debug_print s = if debug then prerr_endline s
let main () =
let schema_file = try Sys.argv.(1) with Invalid_argument _ -> raise Usage in
let schema_doc = Schema_xml.pxp_tree_of schema_file in
debug_print "Parsing schema document ...";
let schema = Schema_parser.parse_schema schema_doc in
for i = 2 to Array.length Sys.argv - 1 do
let instance_stream = Schema_xml.pxp_stream_of_file Sys.argv.(i) in
......@@ -34,17 +44,34 @@ let main () =
raise (XSI_validation_error (sprintf "No declaration found in schema \
for element '%s'" first_element_name)))
in
debug_print "Creating validator for root element ...";
let validator =
Schema_validator.validator_of_elt_decl first_element_decl
in
debug_print "Validating ...";
let value = Schema_validator.validate ~validator instance_stream in
Value.print Format.std_formatter value
debug_print "Printing CDuce value ...";
Value.print Format.std_formatter value;
debug_print "All done!"
with XSI_validation_error msg ->
print_endline (sprintf "Validation error on '%s': %s" Sys.argv.(i) msg);
flush stdout)
done
let _ = main ()
let _ =
try
main ()
with
| Usage ->
prerr_endline
"Usage: validate <schema_document> [ <instance_document> ... ]";
exit 1
| XSD_validation_error msg ->
prerr_endline ("Error validating schema document:\n" ^ msg);
exit 2
| XSI_validation_error msg ->
prerr_endline ("Error validating instance document:\n" ^ msg);
exit 3
(* PROVE VARIE *)
(*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment