caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Alain Frisch <alain@frisch.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] xpath or alternatives
Date: Wed, 30 Sep 2009 16:09:18 +0100	[thread overview]
Message-ID: <20090930150918.GC5126@annexia.org> (raw)
In-Reply-To: <4AC37055.70503@frisch.fr>

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 work:
> 
>   let l = {{ [xml] }} in
>   let l = {{ map l with <domain..>l -> l | _ -> [] }} in
>   let l = {{ map l with <devices..>l -> l | _ -> [] }} in
>   let l = {{ map l with <disk..>l -> l | _ -> [] }} in
>   let l = {{ map l with <source dev=(Latin1 & s) ..>_
>                       | <source file=(Latin1 & s) ..>_-> s
>                       | _ -> [] }} in
>   ...
> 
> let () =
>   let l = {{ [xml] }} in
>   let l = {{ (((l.(<domain..>_)) / .(<devices..>_)) / .(<disk..>_)) / }} in
>   let l = {{ map l with <source dev=(Latin1 & s) ..>_
>                       | <source file=(Latin1 & s) ..>_ -> s
>                       | _ -> [] }} in
>   ..

Thanks Alain.  My latest attempt was similar to your version 1 above,
and it works :-)

Now my code looks like your version 2:

  let xml = from_string xml in
  let xs = {{ [xml] }} in
  let xs = {{ (((xs.(<domain..>_)) / .(<devices..>_)) / .(<disk..>_)) / }} in
  let xs = {{ map xs with
	      | <source dev=(Latin1 & s) ..>_
              | <source file=(Latin1 & s) ..>_ -> [s]
              | _ -> [] }} in
  {: xs :}

(plus the boilerplate for interfacing xml-light and CDuce).

We're getting close to the xpath/perl solution (8 lines vs 3 lines),
with some added type safety and the possibility of validating the XML.

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.

> This uses the constructions e/ and e.(t) as described in the manual.
> 
> That said, using OCamlDuce for this kind of XML data-extraction seems 
> just crazy to me.

I have some comments:

(A) "Subtyping failed" is a very common error, but is only mentioned
briefly in the manual.  I have no idea what these errors mean, so they
should have more explanation.  Here is a simple one which was caused
by me using a value instead of a list (but that is not at all obvious
from the error message):

  Error: Subtyping failed Latin1 <= [ Latin1* ]
  Sample:
  [ Latin1Char ]

(B) I think the interfacing code here:

  http://yquem.inria.fr/~frisch/ocamlcduce/samples/expat/
  http://yquem.inria.fr/~frisch/ocamlcduce/samples/pxp/
  http://yquem.inria.fr/~frisch/ocamlcduce/samples/xmllight/

should be distributed along with ocamlduce.

Rich.

-- 
Richard Jones
Red Hat


  reply	other threads:[~2009-09-30 15:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-28 12:17 Richard Jones
2009-09-28 12:48 ` [Caml-list] " Yaron Minsky
2009-09-28 15:06   ` Till Varoquaux
2009-09-29 23:00     ` Mikkel Fahnøe Jørgensen
2009-09-30 10:16       ` Richard Jones
2009-09-30 10:36         ` Sebastien Mondet
2009-09-30 10:49         ` Mikkel Fahnøe Jørgensen
2009-09-30 11:05         ` Dario Teixeira
2009-09-30 11:57           ` Richard Jones
2009-09-30 12:59             ` Richard Jones
2009-09-30 13:33               ` Till Varoquaux
2009-09-30 14:01                 ` Richard Jones
2009-09-30 14:28                   ` Till Varoquaux
2009-09-30 14:51                   ` Alain Frisch
2009-09-30 15:09                     ` Richard Jones [this message]
2009-09-30 15:18                       ` Alain Frisch
2009-10-28  2:22         ` Daniel Bünzli
2009-09-30 13:39 ` Stefano Zacchiroli
2009-09-30 14:49   ` Gerd Stolpmann
2009-09-30 15:12     ` Stefano Zacchiroli
2009-09-30 15:22       ` Jordan Schatz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090930150918.GC5126@annexia.org \
    --to=rich@annexia.org \
    --cc=alain@frisch.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).