Add option -nw control the wrapping of results in an <xml_result/> node.
[SXSI/xpathcomp.git] / src / nodeSet.ml
index c2265b2..fc0bb0e 100644 (file)
@@ -24,7 +24,7 @@ module type S =
     val iter : ( elt -> unit) -> t -> unit
     val fold : ( elt -> 'a -> 'a) -> t -> 'a -> 'a
     val length : t -> int
-    val serialize : string -> Tree.t -> t -> unit
+    val serialize : string -> bool -> Tree.t -> t -> unit
 
   end
 
@@ -52,11 +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 f _ x =
+    let serialize f _ x =
       let o = open_out f in
-      output_string o "<xml_result>\n";
+      if not b then output_string o "<xml_result>\n";
       output_string o (string_of_int x);
-      output_string o "\n</xml_result>\n";
+      output_char o '\n';
+      if not b then output_string o "</xml_result>\n";
       close_out o
   end
 
@@ -191,19 +192,19 @@ module Mat : S with type t = Tree.node mat =
 
     let length l = l.length
 
-    let serialize name v l =
+    let serialize name v l =
       let fd, finish =
        if name = "-" then Unix.stdout, ignore
        else
          Unix.openfile name [ Unix.O_WRONLY; Unix.O_TRUNC; Unix.O_CREAT ] 0o666,
          Unix.close
       in
-      ignore (Unix.write fd "<xml_result>\n" 0 13);
+      if not b then ignore (Unix.write fd "<xml_result>\n" 0 13);
       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);
+      if not b then ignore (Unix.write fd "</xml_result>\n" 0 14);
       finish fd
 
   end