+
+
+ let tagged_foll t tag =
+ if tag = Tag.attribute || tag = Tag.pcdata then failwith "tagged_foll"
+ else match t with
+ | { doc=d; node=Node(NC n) } -> { t with node = norm (tagged_foll d n tag) }
+ | { doc=d; node=Node(SC (_,n)) } when is_nil n -> { t with node= Nil }
+ | { doc=d; node=Node(SC (_,n)) } ->
+ let nnode =
+ if tag_id d n == tag then n
+ else
+ let n' = tagged_desc d n tag in
+ if is_nil n' then tagged_foll d n tag
+ else n'
+ in {t with node= norm nnode}
+ | _ -> { t with node=Nil }
+
+
+ let tagged_desc t tag =
+ if tag = Tag.attribute || tag = Tag.pcdata then failwith "tagged_desc"
+ else match t with
+ | { doc=d; node=Node(NC n) } -> { t with node = norm (tagged_desc d n tag) }
+ | _ -> { t with node=Nil }
+
+(*
+ let tagged_next t tag =
+ if tag == Tag.attribute || tag == Tag.pcdata then failwith "tagged_next"
+ else
+ match tagged_desc t tag with
+ | { doc = d; node=Nil } -> tagged_foll t tag
+ | x -> x
+*)
+ let subtree_tags t tag =
+ match t with
+ { doc = d; node = Node(NC n) } ->
+ subtree_tags d n tag
+ | _ -> 0
+
+ let tagged_desc_array = ref [| |]
+ let idx = ref 0
+
+ let init_tagged_next t tagid =
+ let l = subtree_tags (root t) tagid
+ in
+ tagged_desc_array := Array.create l { t with node= Nil };
+ let i = ref 0 in
+ let rec collect t =
+ if is_node t then begin
+ if tag t == tagid then
+ begin
+ !tagged_desc_array.(!i) <- t;
+ incr i;
+ end;
+ collect (first_child t);
+ collect (next_sibling t)
+ end;
+ in
+ collect t;
+ idx := 0
+
+ let print_id ppf v =
+ let pr x= Format.fprintf ppf x in
+ match v with
+ { node=Nil } -> pr "NULLT: -1"
+ | { node=String(i) } | { node=Node(SC(i,_)) } -> pr "DocID: %i" (int_of_node i)
+ | { node=Node(NC(i)) } -> pr "Node: %i" (int_of_node i)
+