From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 57AD6BC37 for ; Mon, 28 Sep 2009 14:17:46 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4EABtGwEpQRFuwWWdsb2JhbACaeQEUFwS5ToQeBQ X-IronPort-AV: E=Sophos;i="4.44,466,1249250400"; d="scan'208";a="36995257" Received: from furbychan.cocan.org ([80.68.91.176]) by mail1-smtp-roc.national.inria.fr with ESMTP; 28 Sep 2009 14:17:46 +0200 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1MsFAn-0005I3-Gj for caml-list@inria.fr; Mon, 28 Sep 2009 13:17:45 +0100 Date: Mon, 28 Sep 2009 13:17:45 +0100 To: caml-list@inria.fr Subject: xpath or alternatives Message-ID: <20090928121745.GA19803@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Spam: no; 0.00; ocaml:01 frisch:01 frisch:01 alain:01 alain:01 string:02 library:03 xpath:04 xpath:04 red:92 relies:08 push:08 alternatives:08 perl:09 equivalent:09 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