Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Till Varoquaux <till@p...>
Subject: Re: [Caml-list] xpath or alternatives
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 middle ground between efficiency and simplicity.
The problem you might run into is that XML is a tricky format to deal
with and some of these tools will choke up on complex files
(namespaces,switching character encoding, weird entities in the DTD
etc..).

Till

P.S.: Alain has a good paper on how to compile queries (as done in
cduce). I am just too lazy to look for it.


On Mon, Sep 28, 2009 at 8:48 AM, Yaron Minsky <yminsky@gmail.com> wrote:
> 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
> list.
>
> It was quite effective.  I got the inspiration from a similar tool we have
> for navigating s-expressions, which we should release at some point...
>
> Yaron Minsky
>
> On Sep 28, 2009, at 8:17 AM, Richard Jones <rich@annexia.org> 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);
>>   my @disks = $p->findnodes ('//devices/disk/source/@dev');
>>   push (@disks, $p->findnodes ('//devices/disk/source/@file'));
>>
>> This isn't type safe or pretty, but it is very easy to use for quick
>> and dirty extraction.
>>
>> What is the OCaml equivalent for this sort of code?
>>
>> Alain Frisch has a library called Xpath
>> (http://alain.frisch.fr/soft.html#xpath), but unfortunately this
>> relies on the now obsolete wlex program.
>>
>> Is there a completely alternative way to do this?  Better still, in 3
>> lines of code??
>>
>> Rich.
>>
>> [1] for XML doc, see: http://libvirt.org/formatdomain.html
>>
>> --
>> Richard Jones
>> Red Hat
>>
>> _______________________________________________
>> Caml-list mailing list. Subscription management:
>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>> Archives: http://caml.inria.fr
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>