English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
xpath or alternatives
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-09-30 (10:16)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] xpath or alternatives
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:



Richard Jones
Red Hat