File: delcol.ml

package info (click to toggle)
pxp 1.2.9-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,844 kB
  • sloc: ml: 28,666; xml: 2,597; makefile: 822; sh: 691
file content (55 lines) | stat: -rw-r--r-- 1,257 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(* $Id$
 * ----------------------------------------------------------------------
 *
 *)

(* Read a record-list, delete a column, and print it as XML *)
open Pxp_types;;
open Pxp_document;;
open Pxp_tree_parser;;

let delcol col tree =
  map_tree
    ~pre:
      (fun n -> 
	 match n # node_type with
	     T_element name when name = col ->
	       raise Skip
	   | _ -> n # orphaned_flat_clone)
    tree
;;


let main() =
  let column = ref "" in
  Arg.parse
      [ "-col", Arg.String (fun s -> column := s),
	    " (last-name|first-name|phone)";
      ]
      (fun _ -> raise (Arg.Bad "Bad usage"))
      "usage: sort [ options ]";
  if !column = "" then (
    prerr_endline "Column not specified!";
    exit 1;
  );
  if not(List.mem !column ["last-name"; "first-name"; "phone"]) then (
    prerr_endline ("Unknown column: " ^ !column);
    exit 1
  );
  try
    let dtd = 
      Pxp_dtd_parser.parse_dtd_entity default_config (from_file "record.dtd") in
    let tree = 
      parse_content_entity default_config (from_channel stdin) dtd default_spec
    in
    print_endline "<?xml encoding='ISO-8859-1'?>";
    (delcol !column tree) # write (`Out_channel stdout) `Enc_iso88591
  with
      x ->
	prerr_endline(string_of_exn x);
	exit 1
;;


main();;