Also serialize results in counting mode (prints the count in the output file)
[SXSI/xpathcomp.git] / src / nodeSet.ml
index 944f85c..b8979cc 100644 (file)
@@ -52,7 +52,12 @@ module Count : S with type t = int =
     let fold _ _ _ = failwith "fold not implemented"
     let map _ _ = failwith "map not implemented"
     let length x = x
-    let serialize _ _ _ = ()
+    let serialize f _ x =
+      let o = open_out f in
+      output_string o "<xml_result>\n";
+      output_string o (string_of_int x);
+      output_string o "\n</xml_result>\n";
+      close_out o
   end
 
 type  clist =
@@ -200,8 +205,10 @@ module Mat : S with type t = Tree.node mat =
          Unix.close
       in
       ignore (Unix.write fd "<xml_result>\n" 0 13);
-      iter (fun node -> Tree.print_xml v node fd) l;
-      Tree.flush v fd;
+      if l.length > 0 then begin
+       iter (fun node -> Tree.print_xml v node fd) l;
+       Tree.flush v fd;
+      end;
       ignore (Unix.write fd "</xml_result>\n" 0 14);
       finish fd