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