From: Richard Jones <rich@annexia.org>
To: "Mikkel Fahnøe Jørgensen" <mikkel@dvide.com>
Cc: Till Varoquaux <till@pps.jussieu.fr>,
Yaron Minsky <yminsky@gmail.com>,
"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] xpath or alternatives
Date: Wed, 30 Sep 2009 11:16:22 +0100 [thread overview]
Message-ID: <20090930101622.GA15517@annexia.org> (raw)
In-Reply-To: <caee5ad80909291600x552b5382u67439a4a66f608ef@mail.gmail.com>
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 use the json parser directly.
>
> See the Fleece parser embedded here:
>
> There is also the object abstraction that dives into an object
> hierarchy after parsing, see the Objects module. The combination of
> these two makes it quite easy to work on structured data, but 3 lines
> only come after some xml adaptation work - but you can see many
> one-liner json access in the last part of the file.
>
> http://git.dvide.com/pub/symbiosis/tree/myocamlbuild_config.ml
>
> 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):
>
> http://erratique.ch/software/xmlm
It's interesting you mention xmlm, because I couldn't write
the code using xmlm at all.
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 effort, using xml-light, is around 40 lines:
http://git.et.redhat.com/?p=libguestfs.git;a=blob;f=ocaml/examples/viewer.ml;h=ef6627b1b92a4fff7d4fa1fa4aca63eeffc05ece;hb=HEAD#l322
Rich.
--
Richard Jones
Red Hat
next prev parent reply other threads:[~2009-09-30 10:16 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 [this message]
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
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=20090930101622.GA15517@annexia.org \
--to=rich@annexia.org \
--cc=caml-list@inria.fr \
--cc=mikkel@dvide.com \
--cc=till@pps.jussieu.fr \
--cc=yminsky@gmail.com \
/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