]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/pxp/pxp/examples/validate/validate.ml
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / DEVEL / pxp / pxp / examples / validate / validate.ml
1 (* $Id$
2  * ----------------------------------------------------------------------
3  *
4  *)
5
6
7 open Pxp_document;;
8 open Pxp_yacc;;
9 open Pxp_types;;
10
11 let error_happened = ref false;;
12
13 let print_error e =
14   print_endline (string_of_exn e)
15 ;;
16
17 class warner =
18   object 
19     method warn w =
20       print_endline ("WARNING: " ^ w)
21   end
22 ;;
23
24 let parse debug wf iso88591 filename =
25   try 
26     (* Parse the document: *)
27     let parse_fn =
28       if wf then parse_wfdocument_entity 
29       else 
30         let index = new hash_index in
31         parse_document_entity 
32           ?transform_dtd:None 
33           ~id_index:(index :> 'ext index)
34     in
35     let doc =
36       parse_fn
37           { default_config with 
38               debugging_mode = debug;
39               encoding = if iso88591 then `Enc_iso88591 else `Enc_utf8;
40               idref_pass = true;
41               warner = new warner
42           }
43           (from_file filename)
44           default_spec 
45     in
46     ()
47   with
48       e ->
49         (* Print error; remember that there was an error *)
50         error_happened := true;
51         print_error e
52 ;;
53
54
55 let main() =
56   let debug = ref false in
57   let wf = ref false in
58   let iso88591 = ref false in
59   let files = ref [] in
60   Arg.parse
61       [ "-d",   Arg.Set debug, 
62            "             turn debugging mode on";
63         "-wf",  Arg.Set wf,    
64             "            check only on well-formedness";
65         "-iso-8859-1", Arg.Set iso88591, 
66                     "    use ISO-8859-1 as internal encoding instead of UTF-8";
67       ]
68       (fun x -> files := x :: !files)
69       "
70 usage: pxpvalidate [options] file ...
71
72 - checks the validity of XML documents. See below for list of options.
73
74 <title>PXP - The XML parser for Objective Caml</title>
75
76 List of options:";
77   files := List.rev !files;
78   List.iter (parse !debug !wf !iso88591) !files;
79 ;;
80
81
82 main();
83 if !error_happened then exit(1);;
84
85 (* ======================================================================
86  * History:
87  * 
88  * $Log$
89  * Revision 1.1  2000/11/17 09:57:31  lpadovan
90  * Initial revision
91  *
92  * Revision 1.10  2000/08/30 15:58:41  gerd
93  *      Updated.
94  *
95  * Revision 1.9  2000/07/14 14:57:30  gerd
96  *      Updated: warner
97  *
98  * Revision 1.8  2000/07/14 14:13:15  gerd
99  *      Cosmetic changes.
100  *
101  * Revision 1.7  2000/07/14 14:11:06  gerd
102  *      Updated because of changes of the PXP API.
103  *
104  * Revision 1.6  2000/07/08 21:53:00  gerd
105  *      Updated because of PXP interface changes.
106  *
107  * Revision 1.5  2000/06/04 20:21:55  gerd
108  *      Updated to new module names.
109  *
110  * Revision 1.4  2000/05/01 16:44:57  gerd
111  *      Added check for ID uniqueness.
112  *      Using new error formatter.
113  *
114  * Revision 1.3  1999/11/09 22:27:30  gerd
115  *      The programs returns now an exit code of 1 if one of the
116  * XML files produces an error.
117  *
118  * Revision 1.2  1999/09/01 23:09:56  gerd
119  *      Added the option -wf that switches to well-formedness checking
120  * instead of validation.
121  *
122  * Revision 1.1  1999/08/14 22:20:53  gerd
123  *      Initial revision.
124  *
125  * 
126  *)