(***********************************************************************) (* *) (* 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] *) open Format let doc () = let fd = open_in Sys.argv.(1) in let d = Tree.load_xml_file fd in close_in fd; fprintf err_formatter "Parse Tree OK ! "; 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; fprintf err_formatter "Parse query OK !\n %!"; list else failwith "Use -f" 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 output_string stderr "##### Doc with positions #####\n"; Tree.print_xml_preorder stderr doc (Tree.root doc); output_string stderr "\n"; 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 fprintf err_formatter "\n ### Query: %a" XPath.Ast.print query; 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 (); let asta = Asta.empty in solve_queries tl in solve_queries queries; exit 0