-let attribute = T.hash T.attribute
-let pcdata = T.hash T.pcdata
-
-let pool = ref HMap.empty
-
-
-let add_pool s =
- let hash = T.hash s in
- pool := HMap.add hash s !pool
-
-let clear_pool () =
- pool := HMap.empty;
- add_pool "";
- add_pool T.attribute;
- add_pool T.pcdata
-
-let _ = clear_pool ()
-
-let init l =
- clear_pool ()
-
-let tag s =
- let hash = T.hash s in
- try
- let s' = HMap.find hash !pool
- in
- if s <> s' then
- failwith (Printf.sprintf "hash conflict s1=%s, s2=%s, %i" s s' hash)
- else hash
- with
- Not_found ->
- add_pool s;
- hash
-
-let compare x y = x - y
+type pool
+
+external null_pool : unit -> pool = "caml_xml_tree_nullt"
+external null_tag : unit -> t = "caml_xml_tree_nullt"
+external register_tag : pool -> string -> t = "caml_xml_tree_register_tag"
+external tag_name : pool -> t -> string = "caml_xml_tree_get_tag_name"
+
+let nullt = null_tag ()
+let dummy = nullt
+(* Defined in XMLTree.cpp *)
+let document_node = 0
+let attribute = 1
+let pcdata = 2
+let attribute_data= 3
+let document_node_close = 4
+let attribute_close = 5
+let pcdata_close = 6
+let attribute_data_close= 7
+
+
+let pool = Weak.create 1
+
+let init p = Weak.set pool 0 (Some p)
+
+let get_pool () = match Weak.get pool 0 with
+ | Some x -> x
+ | None -> failwith "Tag.ml: Uninitialized Document"
+
+let tag s = match s with
+ | "<$>" -> pcdata
+ | "<@>" -> attribute
+ | "" -> document_node
+ | "<@$>" -> attribute_data
+ | _ -> register_tag (get_pool()) s
+
+let compare = (-)