6 Xpath.Parser.parse (Ulexing.from_utf8_string p)
9 let () = Table_options.parse () in
11 let fd, close_fd = match !Table_options.input_file with
12 None | Some "-" | Some "/dev/stdin" ->stdin,ignore
14 let fd = open_in input in fd, fun() -> close_in fd
16 (*let inc = open_in Sys.argv.(1) in*)
17 let doc = Naive_tree.load_xml_file fd in
21 (*Hashtbl.clear Query_tree.table_query_tree; il faut vider le hashtbl?????????????????*)
25 !Table_options.queries
28 List.map (fun query -> compile_xpath query) queries
31 let res = eval_query_tree doc [ (Naive_tree.root doc) ] q in
32 print_string "<xml_result num=\"1\" >\n";
33 print_node_list doc res;
34 print_string "</xml_result>\n"
37 let _ = if !Table_options.count then
38 Format.fprintf Format.std_formatter "there are %i nodes\n" !Query_tree.compteur;
42 match !Options.output_file with
43 | None | Some "-" | Some "/dev/stdout" -> stdout
44 | Some f -> open_out f
46 List.iter (fun query ->
47 Logger.msg `STATS "Query: %a " Xpath.Ast.print_path query) queries;
48 List.iter (fun query_tree ->
49 Logger.msg `STATS "@[Query_tree: @\n%a@]" print_query_tree Format.std_formatter query_tree) query_tree_list;
63 (* let query = Xpath.Parser.parse
64 (Ulexing.from_utf8_string Sys.argv.(2))
66 Format.printf "La requete est: %a\n%!"
67 Xpath.Ast.print_path query; *)
69 (* print_endline "Test 1 root.firstchild";
70 let c1 = eval_move doc [ (Naive_tree.root doc) ] Firstchild in
71 print_node_list doc c1;
72 print_endline "Test 2 root.firstchild.firstchild";
73 let c2 = eval_move doc c1 Firstchild in
74 print_node_list doc c2;
75 print_endline "Test 3 root.firstchild.firstchild.nextsibling";
76 let c3 = eval_move doc c2 Nextsibling in
77 print_node_list doc c3;
78 print_endline "Test 4 root.firstchild.firstchild.nextsibling.firstchild";
79 let c4 = eval_move doc c3 Firstchild in
80 print_node_list doc c4;
81 print_endline "Test 5 root.firstchild.firstchild.nextsibling.firstchild.ancestor false";
82 let c5 = eval_axis doc c4 (Ancestor false) in
83 print_node_list doc c5;
84 print_endline "Test 6";
85 let c6 = eval_move doc c5 Prevsibling in
86 print_node_list doc c6;
87 print_endline "Test 7";
88 let c7 = eval_move doc c6 Revfirstchild in
89 print_node_list doc c7;
90 print_endline "Test 8 Child [root]";
91 let c8 = eval_axis doc [Naive_tree.root doc] Child in
92 print_node_list doc c8;
93 print_endline "Test 9 Descendant [b]";
94 let c9 = eval_axis doc c2 (Descendant false) in
95 print_node_list doc c9;
96 print_endline "Test 10 Descendant or self [b]";
97 let c10 = eval_axis doc c2 (Descendant true) in
98 print_node_list doc c10;
99 print_endline "Test 11 FollowingSibling [b]";
100 let c11 = eval_axis doc c2 FollowingSibling in
101 print_node_list doc c11;
102 print_endline "Test 12 Parent [b]";
103 let c12 = eval_axis doc c2 Parent in
104 print_node_list doc c12;
105 print_endline "Test 13 Ancestor or self [b]";
106 let c13 = eval_axis doc c2 (Ancestor true) in
107 print_node_list doc c13;
108 print_endline "Test 14 PrecdingSibling [b]";
109 let c14 = eval_axis doc c2 PrecedingSibling in
110 print_node_list doc c14;
111 print_endline "Test 15 preceding [b]";
112 let c15 = eval_axis doc c2 Preceding in
113 print_node_list doc c15;
114 print_endline "Test 16 Following [b]";
115 let c16 = eval_axis doc c2 Following in
116 print_node_list doc c16;
117 print_endline "Test 17 tag [b]";
118 let c17 = element_by_tag doc (QName.make "b") in
119 print_node_list doc c17;
120 print_endline "Test 18 all nodes";
121 let c18 = all_nodes doc in
122 print_node_list doc c18;
123 print_endline "Test 19 compile_xpath"; *)
126 (*Format.printf "Le document contient: %i noeuds\n%!" (Naive_tree.size doc);
127 let c19 = compile_xpath (parse_xpath "/child::a[child::b or not(following::]") in
128 Format.printf ">> %a\n%!" print_query_tree c19;
129 print_endline "Test 20 eval_query_tree";
130 let res = eval_query_tree doc [ (Naive_tree.root doc) ] c19 in
131 print_node_list doc res;
132 print_endline "Fin";*)