From: Olivier A. <ol...@us...> - 2003-04-23 08:19:53
|
Nicolas Cannasse [Wednesday 23 April 2003] : > > If you want my real opinion, after reading some of the Tim Bray > > discussions recently on the pros and cons of working with XML > > > > http://www.tbray.org/ongoing/When/200x/2003/03/16/XML-Prog > > > > I was looking forward to messing around with a regex style XML > > processor. It looks much easier than any of the event, push, > > pull models of working with XML. > > > > Getting a Ocaml version of this would be cool and be a new > > direction in processing XML. > > The OCaml pattern matching is enough for that, don't you think ? > OCaml : > > let process = function > | Elements ("meta",_,_) -> () > | Elements ("h1",_,_) | Elements ("h2",_,_) | Elements ("h3",_,_) | > Elements ("h4",_,_) -> divert := "head" > | Elements ("img",attr,_) as x -> proc_jpeg (Xml.attrib x "src") > | ... (* and so on *) > in > let rec walk = function > | PCData _ -> () > | Elements (_,_,children) as x -> > process x; > List.iter walk children > in > walk (Xml.parse_in stdin) Here's another solution for reading XML : that's the xml lexer included in the LablGTK sources. It's an ocamllex lexer and you can parse the stream with a camlp4 parser. -- Olivier |