-
- external parse_xml_uri : string -> t = "caml_call_shredder_uri"
- external parse_xml_string : string -> t = "caml_call_shredder_string"
-
- let parse_xml_uri s = Node(0,Tag.tag "",parse_xml_uri s,Nil,ref Nil)
- let parse_xml_string s = Node(0,Tag.tag "",parse_xml_string s,Nil,ref Nil)
- let tstring = function Nil -> "Nil"
- | Node (_,_,_,_,_) -> "Node"
- | String _ -> "String"
-
-
-let print_xml fmt t =
- let pp_str = Format.pp_print_string fmt in
- let rec loop = function Nil -> ()
- | String (s) -> pp_str s
- | Node (_,t,l,r,_) when Tag.equal t Tag.pcdata -> loop l;loop r
- | Node (_,t,l,r,_) ->
- pp_str ("<" ^ (Tag.to_string t));
- ( match l with
- Nil -> pp_str "/>"
- | Node(_,t',atts,children,_) when Tag.equal t' Tag.attribute ->
- (loop_attributes atts;
- match children with
- | Nil -> pp_str "/>"
- | _ ->
- pp_str ">";
- loop children;
- pp_str ("</"^ (Tag.to_string t)^">" )
- )
- | _ -> pp_str ">"; loop l;
- pp_str ("</"^ (Tag.to_string t)^">" );
- );loop r
- and loop_attributes = function
- | Node(_,t,Node(_,_,String(s),_,_),r,_) ->
- pp_str (" "^(Tag.to_string t)^"=\""^ s ^"\"") ;
- loop_attributes r
- | _ -> ()
-
- in
- loop t
-
-let print_xml fmt =
- function Node(i,t,l,_,_) -> print_xml fmt (Node(i,t,l,Nil,ref Nil))
- | t -> print_xml fmt t
-
-
-(* a bit ugly but inlining like this makes serialization faster *)
-
-let print_xml_fast outc t =
- let rec loop = function Nil -> ()
- | String (s) -> output_string outc s
- | Node (_,t,l,r,_) when Tag.equal t Tag.pcdata -> loop l;loop r
- | Node (_,t,l,r,_) -> let t = Tag.to_string t in
- output_char outc '<';
- output_string outc t;
- ( match l with
- Nil -> output_string outc "/>"
- | Node(_,t',atts,children,_) when Tag.equal t' Tag.attribute ->
- (loop_attributes atts;
- match children with
- | Nil -> output_string outc "/>"
- | _ ->
- output_char outc '>';
- loop children;
- output_string outc "</";
- output_string outc t;
- output_char outc '>' )
- | _ ->
- output_char outc '>';
- loop l;
- output_string outc "</";
- output_string outc t;
- output_char outc '>'
- );loop r
- and loop_attributes = function
- | Node(_,t,Node(_,_,String(s),_,_),r,_) ->
- output_char outc ' ';
- output_string outc (Tag.to_string t);
- output_string outc "=\"";
- output_string outc s;
- output_char outc '"';
- loop_attributes r
- | _ -> ()
+let compare_node : 'a node -> 'a node -> int = (-)
+let equal_node : 'a node -> 'a node -> bool = (==)
+
+(* abstract type, values are pointers to a XMLTree C++ object *)
+
+external int_of_node : 'a node -> int = "%identity"
+
+external parse_xml_uri : string -> int -> bool -> bool -> tree = "caml_call_shredder_uri"
+external parse_xml_string : string -> int -> bool -> bool -> tree = "caml_call_shredder_string"
+
+external save_tree : tree -> string -> unit = "caml_xml_tree_save"
+external load_tree : string -> int -> tree = "caml_xml_tree_load"
+
+external nullt : unit -> 'a node = "caml_xml_tree_nullt"
+
+let nil : 'a node = Obj.magic (-1)
+
+external text_get_text : tree -> [`Text] node -> string = "caml_text_collection_get_text"
+
+external text_is_empty : tree -> [`Text ] node -> bool = "caml_text_collection_empty_text"
+
+let text_is_empty t n =
+ (equal_node nil n) || text_is_empty t n
+
+external get_cached_text : tree -> [`Text ] node -> string = "caml_text_collection_get_cached_text"
+
+
+let text_get_text t n =
+ if equal_node nil n then ""
+ else get_cached_text t n