- let descr t = t.node
-
- let nts = function
- Nil -> "Nil"
- | String i -> Printf.sprintf "String %i" i
- | Node (NC t) -> Printf.sprintf "Node (NC %i)" (int_of_node t)
- | Node (SC (t,i)) -> Printf.sprintf "Node (SC (%i,%i))" (int_of_node t) (int_of_node i)
-
-
- let root n = { n with node = norm (Tree.root n.doc) }
- let is_root n = match n.node with
- | Node(NC t) when (Tree.root n.doc) == t -> true
- | _ -> false
-
- let parent n =
- let node' =
- match n.node with
- | Node(NC t) ->
- let txt = prev_text n.doc t in
- if Text.is_empty n.doc txt then
- Node(NC (Tree.parent n.doc t))
- else
- Node(SC (txt,t))
- | Node(SC(t,_)) -> Node (NC(parent_doc n.doc t))
- | _ -> failwith "parent"
- in
- { n with node = node' }
-
- let first_child n =
- let node' =
- match n.node with
- | Node (NC t) when is_leaf n.doc t ->
- let txt = my_text n.doc t in
- if Text.is_empty n.doc txt
- then Nil
- else Node(SC (txt,Tree.nil))
- | Node (NC t) ->
- let fs = first_child n.doc t in
- let txt = prev_text n.doc fs in
- if Text.is_empty n.doc txt
- then norm fs
- else Node (SC (txt, fs))
- | Node(SC (i,_)) -> String i
- | Nil | String _ -> failwith "first_child"
- in
- { n with node = node'}
-
-
- let next_sibling n =
- let node' =
- match n.node with
- | Node (SC (_,ns)) -> norm ns
- | Node(NC t) ->
- let ns = next_sibling n.doc t in
- let txt = next_text n.doc t in
- if Text.is_empty n.doc txt
- then norm ns
- else Node (SC (txt, ns))
- | Nil | String _ -> failwith "next_sibling"
- in
- { n with node = node'}
-
-
- let left = first_child
- let right = next_sibling
-
- let id =
- function { doc=d; node=Node(NC n)} -> node_xml_id d n
- | { doc=d; node=Node(SC (i,_) )} -> text_xml_id d i
- | _ -> failwith "id"
-
- let tag =
- function { node=Node(SC _) } -> Tag.pcdata
- | { doc=d; node=Node(NC n)} -> tag_id d n
- | _ -> failwith "tag"
-
-(* let tag_id =
- function { node=Node(SC _) } -> ()
- | { doc=d; node=Node(NC n)} -> tag_id d n
- | _ -> ()
-*)
- let string_below t id =
- let strid = parent_doc t.doc id in
- match t.node with
- | Node(NC(i)) ->
- (Tree.equal i strid) || (is_ancestor t.doc i strid)
- | Node(SC(i,_)) -> Text.equal i id
- | _ -> false
-
-
- 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 text_below t =
+ let l = Array.length !contains_array in
+ match t.node with
+ | Node(n) ->
+ let i,j = tree_doc_ids t.doc n in
+ let id = if l == 0 then i else (array_find !contains_array i j)
+ in
+(* Printf.printf "Looking for text below node %i with tag %s in range %i %i, in array : [|\n%!"
+ n (Tag.to_string (tree_tag_id t.doc n)) i j;
+ Array.iter (fun i -> Printf.printf "%i " (int_of_node i )) !contains_array;
+ Printf.printf "|]\nResult is %i\n%!" id; *)
+ if id == nil then
+ { t with node=Nil }
+ else
+ { t with node = Text(id, tree_next_sibling t.doc (tree_prev_doc t.doc id)) }
+ | _ -> (*Printf.printf "Here\n%!"; *)
+ { t with node = Nil }