(***********************************************************************) (* *) (* TAToo *) (* *) (* Kim Nguyen, LRI UMR8623 *) (* Université Paris-Sud & CNRS *) (* *) (* Copyright 2010-2012 Université Paris-Sud and Centre National de la *) (* Recherche Scientifique. All rights reserved. This file is *) (* distributed under the terms of the GNU Lesser General Public *) (* License, with the special exception on linking described in file *) (* ../LICENSE. *) (* *) (***********************************************************************) (** use: [./test xml_file -f XPath_queries_file] one query per line [XPath_querie_file], output a solution per line. *) open Format let doc () = let fd = open_in Sys.argv.(1) in let d = Tree.load_xml_file fd in close_in fd; d let query () = let arg2 = Sys.argv.(2) in if arg2 = "-f" then let fq = open_in Sys.argv.(3) in let rec list_qu fq list = try let q = XPath.parse_file fq in list_qu fq (q::list) with _ -> list in let list = list_qu fq [] in close_in fq; list else failwith "Use ./test xml_file -f XPath_queries_file" let compute_run doc query = let run = Run.compute doc query in run let () = let flag = Array.length Sys.argv = 5 in Format.pp_set_margin err_formatter 80; let doc = doc () in let queries = query () in let rec print_selec fmt l = match l with | [x] -> fprintf fmt "%s" (string_of_int x) | x :: tl -> fprintf fmt "%s" ((string_of_int x)^"; ");print_selec fmt tl | [] -> fprintf fmt "%s" "ø" in let rec solve_queries = function | [] -> () | query :: tl -> let asta = Compil.trans query in let selected_nodes = Run.selected_nodes doc asta in let run = compute_run doc asta in if flag then fprintf err_formatter " ### Query: %a" XPath.Ast.print query else (); fprintf err_formatter "@. ### Selected nodes: {%a}@." print_selec selected_nodes; if flag then begin Asta.print err_formatter asta; Run.print err_formatter run; end else (); solve_queries tl in solve_queries queries; exit 0