From a0b2c9ed65ef81b9c61ce459bec6b9a5c3563862 Mon Sep 17 00:00:00 2001 From: Thomas Gazagnaire Date: Wed, 16 Sep 2009 15:37:14 +0100 Subject: [PATCH] [rpc-light] modify xml-light2 to expose few more accessors, in order to look much more like xml-light. --- xml-light2/xml.ml | 16 ++++++++++++++++ xml-light2/xml.mli | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/xml-light2/xml.ml b/xml-light2/xml.ml index a8d6059..af197dd 100644 --- a/xml-light2/xml.ml +++ b/xml-light2/xml.ml @@ -195,3 +195,19 @@ let to_bigbuffer xml = let buffer = Bigbuffer.make () in to_fct xml (fun s -> Bigbuffer.append_substring buffer s 0 (String.length s)); buffer + +(* helpers functions *) +exception Not_pcdata of string +exception Not_element of string + +let pcdata = function + | PCData x -> x + | e -> raise (Not_pcdata (to_string e)) + +let children = function + | Element (_,_,c) -> c + | e -> raise (Not_element (to_string e)) + +let tag = function + | Element (x,_,_) -> x + | e -> raise (Not_element (to_string e)) diff --git a/xml-light2/xml.mli b/xml-light2/xml.mli index efc8f58..667158f 100644 --- a/xml-light2/xml.mli +++ b/xml-light2/xml.mli @@ -22,3 +22,10 @@ val to_fct_fmt : xml -> (string -> unit) -> unit val to_string : xml -> string val to_string_fmt : xml -> string val to_bigbuffer : xml -> Bigbuffer.t + +(** helper functions *) +exception Not_pcdata of string +exception Not_element of string +val pcdata : xml -> string +val children : xml -> xml list +val tag : xml -> string -- 2.39.5