diff options
Diffstat (limited to 'lib/xml.ml')
-rw-r--r-- | lib/xml.ml | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -1,5 +1,6 @@ open Lwt.Syntax +exception Malformed exception InvalidStanza of string type element = { @@ -9,9 +10,9 @@ type element = { children : (element, string) Either.t list; } -(** [tree s] is a promise to an [element option] representing the XML element inside of +(** [tree s] is a promise to an [element] representing the XML element inside of stream [s], if [s] is a complete element from start to end. *) -let tree s : element option Lwt.t = +let tree s : element Lwt.t = let element (namespace, name) attributes children = Either.Left { namespace; @@ -26,8 +27,11 @@ let tree s : element option Lwt.t = children; } and text ss = Either.Right (String.concat "" ss) in - let+ opt_el = Markup_lwt.tree ~text ~element s in - Option.bind opt_el (Either.fold ~left:Option.some ~right:(fun _ -> None)) + let* el = Markup_lwt.tree ~text ~element s + in match el with + | Some Left el -> Lwt.return el + | _ -> Lwt.fail Malformed +(* Option.bind opt_el (Either.fold ~left:Option.some ~right:(fun _ -> None)) *) (** [element_to_string element] is a string representation of the underlying XML in [element], for debugging purposes. |