aboutsummaryrefslogtreecommitdiff
path: root/lib/xml.ml
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-19 15:08:51 +0200
committerClombrong <cromblong@egregore.fun>2025-06-19 17:56:24 +0200
commitb0d45628c184701c91cafa81197114e7570ad129 (patch)
tree3b0ee5311230c340ef1f00eaa917a7c6130ce073 /lib/xml.ml
parent28d123ff109663ac8849ef0c83f6f2e22bdcd88c (diff)
feat(xml): add conversion function from Markup.ml to element
Diffstat (limited to 'lib/xml.ml')
-rw-r--r--lib/xml.ml20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/xml.ml b/lib/xml.ml
index 8b99049..c73bad6 100644
--- a/lib/xml.ml
+++ b/lib/xml.ml
@@ -1,6 +1,26 @@
+open Markup
+
type element = {
namespace : string;
local_name : string;
attributes : (string * string) list;
children : (element, string) Either.t list;
}
+
+let tree s : element option =
+ let element (namespace, name) attributes children =
+ Either.Left {
+ namespace;
+ local_name=name;
+ attributes=List.filter_map
+ (fun ((ns, name), content) ->
+ (* remove xmlns -- we don't need it. *)
+ match ns with
+ | "http://www.w3.org/2000/xmlns/" -> None
+ | _ -> Some (name, content))
+ attributes;
+ children;
+ }
+ and text ss = Either.Right (String.concat "" ss) in
+ let opt_el = tree ~text ~element s in
+ Option.bind opt_el (Either.fold ~left:Option.some ~right:(fun _ -> None))