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]
24 let fd = open_in Sys.argv.(1) in
25 let d = Tree.load_xml_file fd in
27 fprintf err_formatter "Parse Tree OK ! ";
32 let arg2 = Sys.argv.(2) in
34 then let fq = open_in Sys.argv.(3) in
35 let rec list_qu fq list =
37 (match XPath.parse_file fq with
38 | q -> list_qu fq (q::list)
41 let list = list_qu fq [] in
43 fprintf err_formatter "Parse query OK ! ";
45 else failwith "Use -f"
47 let build_asta query =
48 let asta = Compil.trans query in
49 fprintf err_formatter "Compil OK ! ";
52 let compute_run doc query =
53 let run = Run.compute doc query in
54 fprintf err_formatter "Run OK ! \n";
58 Format.pp_set_margin err_formatter 80;
60 output_string stderr "##### Doc with positions #####\n";
61 Tree.print_xml_preorder stderr doc (Tree.root doc);
62 output_string stderr "\n";
63 let queries = query () in
64 let rec solve_queries = function
67 let asta = build_asta query in
68 let selected_nodes = Run.selected_nodes doc asta in
69 fprintf err_formatter "\n ### Query: %a\n"
70 XPath.Ast.print query;
71 let rec print_selec fmt l = match l with
72 | [x] -> fprintf fmt "%s" (string_of_int x)
73 | x :: tl -> fprintf fmt "%s" ((string_of_int x)^"; ");print_selec fmt tl
74 | [] -> fprintf fmt "%s" "ø" in
75 fprintf err_formatter "@. ### Selected nodes: {%a}@."
76 print_selec selected_nodes in
77 solve_queries queries;