diff options
-rw-r--r-- | src/reference_tree.ml | 2 | ||||
-rw-r--r-- | src/vytree.ml | 4 | ||||
-rw-r--r-- | src/vytree.mli | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml index f61feaa..24e02a5 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -118,7 +118,7 @@ let rec insert_from_xml basepath reftree xml = let data = {data with node_type=node_type; owner=node_owner} in let name = Xml.attrib xml "name" in let path = basepath @ [name] in - let new_tree = Vytree.insert reftree path data in + let new_tree = Vytree.insert_maybe reftree path data in (match node_type with | Leaf -> new_tree | _ -> diff --git a/src/vytree.ml b/src/vytree.ml index bd73776..ace587b 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -88,6 +88,10 @@ let rec insert ?(position=Default) ?(children=[]) node path data = let s = Printf.sprintf "Non-existent intermediary node: \'%s\'" name in raise (Insert_error s) +let insert_maybe ?(position=Default) node path data = + try insert ~position:position node path data + with Duplicate_child -> node + let sorted_children_of_node cmp node = let names = list_children node in let names = List.sort cmp names in diff --git a/src/vytree.mli b/src/vytree.mli index 377c9aa..a7bf680 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -23,6 +23,8 @@ val replace : 'a t -> 'a t -> 'a t val insert : ?position:position -> ?children:('a t list) -> 'a t -> string list -> 'a -> 'a t +val insert_maybe : ?position:position -> 'a t -> string list -> 'a -> 'a t + val insert_multi_level : 'a -> 'a t -> string list -> string list -> 'a -> 'a t val merge_children : ('a -> 'a -> 'a) -> (string -> string -> int) -> 'a t -> 'a t |