let element_of_xml ?expected xml = let open Webdav in try let n = Xml.tag xml in begin match expected with | None -> Ok n | Some expected -> if String.compare n expected = 0 then begin Ok n end else begin Error (`Bad_request, sprintf "Expected <%s>, got <%s>" expected n) end end with Xml.Not_element _ -> Error (`Bad_request, sprintf "Expected an element, got %s" (Xml.to_string xml)) let webdav_result_map f = function | Webdav.Error _ as err -> err | Webdav.Ok x -> f x let propfind_request_of_prop prop = let open Webdav in List.fold_left (fun acc ch -> webdav_result_map (fun acc -> webdav_result_map (fun x -> Ok (x :: acc) ) (element_of_xml ch)) acc) (Ok []) (Xml.children prop)