From 3b2b0d009ba7962da8b12c62f119fa4b1178e858 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 22 Apr 2015 14:27:54 +0600 Subject: Add a function for looking up xml-light tag children. It now lives in a Util, a module that implements the adopter design pattern. --- src/util.ml | 11 +++++++++++ src/util.mli | 1 + 2 files changed, 12 insertions(+) create mode 100644 src/util.ml create mode 100644 src/util.mli (limited to 'src') diff --git a/src/util.ml b/src/util.ml new file mode 100644 index 0000000..33c90a2 --- /dev/null +++ b/src/util.ml @@ -0,0 +1,11 @@ +(* Unavoidable module for functions that don't fit anywhere else *) + +let find_xml_child name xml = + let find_aux e = + match e with + | Xml.Element (name', _, _) when name' = name -> true + | _ -> false + in + match xml with + | Xml.Element (_, _, children) -> List.find find_aux children + | Xml.PCData _ -> raise Not_found diff --git a/src/util.mli b/src/util.mli new file mode 100644 index 0000000..e4ced4f --- /dev/null +++ b/src/util.mli @@ -0,0 +1 @@ +val find_xml_child : string -> Xml.xml -> Xml.xml -- cgit v1.2.3