Re: [Caml-list] xpath or alternatives

2009-10-27 Thread Daniel Bünzli
Sorry for the late reply. On Wed, Sep 30, 2009 at 01:00:15AM +0200, Mikkel Fahnøe Jørgensen wrote: Otherwise there is xmlm which is self-contained in single xml file, and as I recall, has some sort of zipper navigator. (I initially intended to use it before deciding on the json format): The

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Richard Jones
On Wed, Sep 30, 2009 at 01:00:15AM +0200, Mikkel Fahnøe Jørgensen wrote: In line with what Yaron suggests, you can use a combinator parser. I do this to parse json, and this parser could be adapted to xml by focusing on basic syntax and ignoring the details, or you could prefilter xml and

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Sebastien Mondet
The discussion here has got quite theoretical, but it's not helping me to write the original 3 lines of Perl in OCaml.    my $p = XML::XPath-new (xml = $xml);    my @disks = $p-findnodes ('//devices/disk/source/@dev');    push (@disks, $p-findnodes ('//devices/disk/source/@file')); My best

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Mikkel Fahnøe Jørgensen
2009/9/30 Richard Jones r...@annexia.org: On Wed, Sep 30, 2009 at 01:00:15AM +0200, Mikkel Fahnøe Jørgensen wrote: In line with what Yaron suggests, you can use a combinator parser. It's interesting you mention xmlm, because I couldn't write the code using xmlm at all. If you can manage to

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Dario Teixeira
Hi, Ocamlduce has been mentioned before in this thread, but I didn't catch the reason why it has been discarded as a solution. Is it because you don't want to carry the extra (large) dependency, or is there some other reason? And on the subject of simple XML parsers for Ocaml, there's also the

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Richard Jones
On Wed, Sep 30, 2009 at 04:05:03AM -0700, Dario Teixeira wrote: Hi, Ocamlduce has been mentioned before in this thread, but I didn't catch the reason why it has been discarded as a solution. Is it because you don't want to carry the extra (large) dependency, or is there some other reason?

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Richard Jones
On Wed, Sep 30, 2009 at 12:57:23PM +0100, Richard Jones wrote: On Wed, Sep 30, 2009 at 04:05:03AM -0700, Dario Teixeira wrote: Hi, Ocamlduce has been mentioned before in this thread, but I didn't catch the reason why it has been discarded as a solution. Is it because you don't want to

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Till Varoquaux
OCamlduce (Alain correct me if I am wrong) basically maintains two separate type systems side by side (the Xduce one and the Ocaml one). This is done in order to make Ocamlduce maintainable by keeping a clear separation. As a result you have to explicitly convert values between type systems using

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Stefano Zacchiroli
On Mon, Sep 28, 2009 at 01:17:45PM +0100, Richard Jones wrote: I need to do some relatively simple extraction of fields from an XML document. In Perl I would use xpath, very specifically if $xml was an XML document[1] stored as a string, then: my $p = XML::XPath-new (xml = $xml);

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Richard Jones
On Wed, Sep 30, 2009 at 09:33:07AM -0400, Till Varoquaux wrote: OCamlduce (Alain correct me if I am wrong) basically maintains two separate type systems side by side (the Xduce one and the Ocaml one). This is done in order to make Ocamlduce maintainable by keeping a clear separation. As a

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Till Varoquaux
If I am not mistaken you are selecting a domain whose first child is a device node whose only child is disk node ... instead of: domain..[devices..[disk..[source dev=(Latin1 s) .._]]] you should aim for something in the vein of: domain .. [_* (devices.. (disk..(source dev=(Latin1 s)| souce

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Gerd Stolpmann
Am Mittwoch, den 30.09.2009, 15:39 +0200 schrieb Stefano Zacchiroli: On Mon, Sep 28, 2009 at 01:17:45PM +0100, Richard Jones wrote: I need to do some relatively simple extraction of fields from an XML document. In Perl I would use xpath, very specifically if $xml was an XML document[1]

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Alain Frisch
Richard Jones wrote: let devs = {{ map [xml] with | domain..[devices..[disk..[source dev=(Latin1 s) .._]]] | domain..[devices..[disk..[source file=(Latin1 s) .._]]] - [s] | _ - [] }} in The following should work: let l = {{ [xml] }} in let l = {{ map l with domain..l - l |

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Richard Jones
On Wed, Sep 30, 2009 at 04:51:01PM +0200, Alain Frisch wrote: Richard Jones wrote: let devs = {{ map [xml] with | domain..[devices..[disk..[source dev=(Latin1 s) .._]]] | domain..[devices..[disk..[source file=(Latin1 s) .._]]] - [s] | _ - [] }} in The following should

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Stefano Zacchiroli
On Wed, Sep 30, 2009 at 04:49:37PM +0200, Gerd Stolpmann wrote: No. However, there is a little XPath evaluator in SVN: https://godirepo.camlcity.org/svn/lib-pxp/trunk/src/pxp-engine/pxp_xpath.ml Cool, and you have even already implemented all of the XPath 1.0 standard library! I have never

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Alain Frisch
Richard Jones wrote: On the other hand, the code is hard to understand. It's not clear to me what the .( ) syntax means, nor why there is an apparently trailing / character. From the manual: If the x-expression e evaluates to an x-sequence, the construction e/ will result in a new

Re: [Caml-list] xpath or alternatives

2009-09-30 Thread Jordan Schatz
I hope this is germane, I am very new to Ocaml. Do these help at all? http://packages.debian.org/sid/libxml-light-ocaml-dev http://tech.motion-twin.com/xmllight.html I expect it wouldn't be to difficult to write a wrapper around libxml http://xmlsoft.org/index.html -Jordan

Re: [Caml-list] xpath or alternatives

2009-09-29 Thread Mikkel Fahnøe Jørgensen
In line with what Yaron suggests, you can use a combinator parser. I do this to parse json, and this parser could be adapted to xml by focusing on basic syntax and ignoring the details, or you could prefilter xml and use the json parser directly. See the Fleece parser embedded here: There is

[Caml-list] xpath or alternatives

2009-09-28 Thread Richard Jones
I need to do some relatively simple extraction of fields from an XML document. In Perl I would use xpath, very specifically if $xml was an XML document[1] stored as a string, then: my $p = XML::XPath-new (xml = $xml); my @disks = $p-findnodes ('//devices/disk/source/@dev'); push

Re: [Caml-list] xpath or alternatives

2009-09-28 Thread Yaron Minsky
I don't have the code in front of me, but I've done something like this using the list monad. i.e., using bind (= concat-map) and map chained together, along with a couple operators I wrote for lifting bits of XML documents into lists, by say returning the subnodes of the present node as a

Re: [Caml-list] xpath or alternatives

2009-09-28 Thread Till Varoquaux
There are a few projects out here: xtisp http://www.xtisp.org xstream http://yquem.inria.fr/~frisch/xstream/ and of course the good old cduce/xduce/ocamlduce. All in all naive querying is not hard and tree automata: (e.g.) http://www.grappa.univ-lille3.fr/~filiot/tata/ can provide a good