1 (***********************************************************************)
5 (* Kim Nguyen, LRI UMR8623 *)
6 (* Université Paris-Sud & CNRS *)
8 (* Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
9 (* Recherche Scientifique. All rights reserved. This file is *)
10 (* distributed under the terms of the GNU Lesser General Public *)
11 (* License, with the special exception on linking described in file *)
14 (***********************************************************************)
17 (** use: [./test xml_file -f XPath_queries_file]
18 one query per line [XPath_querie_file], output
25 let fd = open_in Sys.argv.(1) in
26 let d = Tree.load_xml_file fd in
32 let arg2 = Sys.argv.(2) in
34 then let fq = open_in Sys.argv.(3) in
35 let rec list_qu fq list =
36 try let q = XPath.parse_file fq in
39 let list = list_qu fq [] in
42 else failwith "Use ./test xml_file -f XPath_queries_file"
44 let compute_run doc query =
45 let run = Run.compute doc query in
49 let flag = Array.length Sys.argv = 5 in
50 Format.pp_set_margin err_formatter 80;
52 let queries = query () in
53 let rec print_selec fmt l = match l with
54 | [x] -> fprintf fmt "%s" (string_of_int x)
55 | x :: tl -> fprintf fmt "%s" ((string_of_int x)^"; ");print_selec fmt tl
56 | [] -> fprintf fmt "%s" "ø" in
57 let rec solve_queries = function
60 let asta = Compil.trans query in
61 let selected_nodes = Run.selected_nodes doc asta in
62 let run = compute_run doc asta in
65 fprintf err_formatter " ### Query: %a"
68 fprintf err_formatter "@. ### Selected nodes: {%a}@."
69 print_selec selected_nodes;
72 Asta.print err_formatter asta;
73 Run.print err_formatter run;
77 solve_queries queries;