]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/pxp/pxp/examples/simple_transformation/delcol.ml
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / DEVEL / pxp / pxp / examples / simple_transformation / delcol.ml
1 (* $Id$
2  * ----------------------------------------------------------------------
3  *
4  *)
5
6 (* Read a record-list, delete a column, and print it as XML *)
7 open Pxp_types;;
8 open Pxp_document;;
9 open Pxp_yacc;;
10
11 let delcol col tree =
12   map_tree
13     ~pre:
14       (fun n -> 
15          match n # node_type with
16              T_element name when name = col ->
17                raise Skip
18            | _ -> n # orphaned_flat_clone)
19     tree
20 ;;
21
22
23 let main() =
24   let column = ref "" in
25   Arg.parse
26       [ "-col", Arg.String (fun s -> column := s),
27             " (last-name|first-name|phone)";
28       ]
29       (fun _ -> raise (Arg.Bad "Bad usage"))
30       "usage: sort [ options ]";
31   if !column = "" then (
32     prerr_endline "Column not specified!";
33     exit 1;
34   );
35   if not(List.mem !column ["last-name"; "first-name"; "phone"]) then (
36     prerr_endline ("Unknown column: " ^ !column);
37     exit 1
38   );
39   try
40     let dtd = parse_dtd_entity default_config (from_file "record.dtd") in
41     let tree = 
42       parse_content_entity default_config (from_channel stdin) dtd default_spec
43     in
44     print_endline "<?xml encoding='ISO-8859-1'?>";
45     (delcol !column tree) # write (Out_channel stdout) `Enc_iso88591
46   with
47       x ->
48         prerr_endline(string_of_exn x);
49         exit 1
50 ;;
51
52
53 main();;
54
55 (* ======================================================================
56  * History:
57  * 
58  * $Log$
59  * Revision 1.1  2000/11/17 09:57:32  lpadovan
60  * Initial revision
61  *
62  * Revision 1.2  2000/08/24 09:42:52  gerd
63  *      Updated a comment.
64  *
65  * Revision 1.1  2000/08/24 09:39:59  gerd
66  *      Initial revision.
67  *
68  * 
69  *)