From: Nicolas C. <war...@fr...> - 2003-04-23 07:26:46
|
> > resulting library binary won't exceed few KB. > > PXP have to go its own way, there is really enough space and need for one > > library like Xml Light, don't you think ? > > 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 ? while (<STDIN>) { next if (X<meta>X); if (X<h1>|<h2>|<h3>|<h4>X) { $divert = 'head'; } elsif (X<img src="/^(.*\.jpg)$/i>X) { &proc_jpeg($1); } # and so on... } 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) Of course, this version is first reading all stdin and parsing it as a Xml tree before processing, but I'm thinking right now of adding Lazy xml processing to Xml Light so you parse only what you need. Others things possible are to generate a MLI file from an DTD which will provide all types and conversion functions from and to XML. Nicolas Cannasse |