1 (******************************************************************************)
2 (* SXSI : XPath evaluator *)
3 (* Kim Nguyen (Kim.Nguyen@nicta.com.au) *)
4 (* Copyright NICTA 2008 *)
5 (* Distributed under the terms of the LGPL (see LICENCE) *)
6 (******************************************************************************)
10 if Tree.Binary.is_node v
12 let tag = Tree.Binary.tag v
14 let acc = aux (Ptset.add tag acc) (Tree.Binary.first_child v)
16 aux (Ptset.add tag acc) (Tree.Binary.next_sibling v)
23 if Array.length (Sys.argv) <> 2
26 Printf.printf "usage: %s file.xml\n" (Sys.argv.(0));
33 Tree.Binary.parse_xml_uri Sys.argv.(1)
37 Tree.Binary.load Sys.argv.(1)
40 Printf.printf "Error parsing document\n";
43 let _ = Tag.init (Tree.Binary.tag_pool doc)
45 let tags = (collect_tags doc)
48 let _ = Tree.Binary.test_xml_tree Format.std_formatter tags doc
51 let _ = Printf.printf "Testing //a with jumping\n"
54 let rec test_a dir t acc ctx =
55 if Tree.Binary.is_node t
58 if (Tree.Binary.tag t) == (Tag.tag "a")
59 then Ata.TS.cons t acc
62 let first = Tree.Binary.tagged_below t Ptset.empty (Ptset.singleton (Tag.tag "a"))
63 and next = Tree.Binary.tagged_next t Ptset.empty (Ptset.singleton (Tag.tag "a")) ctx
66 Printf.printf "t is :";
67 Tree.Binary.print_xml_fast stdout t;
68 Printf.printf " called from %s of " (if dir then "below" else "next");
69 Tree.Binary.print_xml_fast stdout ctx;
70 if (Tree.Binary.is_node next)
72 Printf.printf ", Next a is %!";
73 Tree.Binary.print_xml_fast stdout next;
76 Printf.printf ", Next a is empty!";
79 test_a false next (test_a true first acc t) t
83 let rec test_text dir t acc ctx =
84 if Tree.Binary.is_node t
87 if (Tree.Binary.tag t) == (Tag.pcdata)
88 then Ata.TS.cons t acc
91 let first = Tree.Binary.text_below t
92 and next = Tree.Binary.text_next t ctx
96 Printf.printf "t is :";
97 Tree.Binary.print_xml_fast stdout t;
98 Printf.printf " called from %s of " (if dir then "below" else "next");
99 Tree.Binary.print_xml_fast stdout ctx;
100 if (Tree.Binary.is_node first)
102 Printf.printf "First (text) is %!";
103 Tree.Binary.print_xml_fast stdout first;
106 Printf.printf "First (text) is empty!";
107 if (Tree.Binary.is_node next)
109 Printf.printf ", Next (text) is %!";
110 Tree.Binary.print_xml_fast stdout next;
113 Printf.printf ", Next (text) is empty!";
116 test_text false next (test_text true first acc t) ctx
120 let r = test_a true doc Ata.TS.empty doc;;
122 let _ = Printf.printf "==> %i nodes\n" (Ata.TS.length r)
123 let _ = Ata.TS.iter (fun t -> Tree.Binary.print_xml_fast stdout t; print_newline();) r
126 let _ = Tree.Binary.init_contains doc "car"
128 let r = test_text true doc Ata.TS.empty doc
129 let _ = Printf.printf "==> %i nodes\n" (Ata.TS.length r)
130 (* let _ = Ata.TS.iter (fun t -> Tree.Binary.print_xml_fast stdout t; print_newline();) r *)
135 let t1 = Unix.gettimeofday () in
137 let t2 = Unix.gettimeofday () in
138 let t = (1000. *.(t2 -. t1)) in
139 Printf.eprintf " %fms\n%!" t ;
142 let _ = Printf.eprintf "Timing jump //keyword ... "
143 let _ = time Tree.Binary.test_jump doc (Tag.tag "keyword")