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=2.8 required=5.0 tests=DNS_FROM_RFC_POST,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id BE413BC37 for ; Mon, 28 Sep 2009 14:49:05 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsgBAJtNwErRVd3Cjmdsb2JhbACPXIFxiHg/AQEBAQkLCAkRBaosgTSODwEDAgWEGQU X-IronPort-AV: E=Sophos;i="4.44,466,1249250400"; d="scan'208";a="47433916" Received: from mail-qy0-f194.google.com ([209.85.221.194]) by mail4-smtp-sop.national.inria.fr with ESMTP; 28 Sep 2009 14:49:05 +0200 Received: by qyk32 with SMTP id 32so3296160qyk.1 for ; Mon, 28 Sep 2009 05:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:references:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:x-mailer :mime-version:subject:date:cc; bh=G+A7NKmyxIT/V3iL6S/EKbk8B/6nNx5Ycdhjv/tS0h8=; b=qopVY1IX/UxwjPgzTX84JI1BDT7ZGPOZ9FuFD0Q3p9MVbJc+6LAdQb5sJY2G0R4uWx C9jjxs914zmlgTrCInJ+jp/heWWrSISSRChV2f0MX5R3gM9xWKjf86Hrranpet+NI7+B WvzpmHJjby6dXP6Q8cSiIzNaI7TbfnSygFDJc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=references:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:x-mailer:mime-version:subject:date:cc; b=eaKFxtr7TX5O28eDpAl9icxZLWk5sYJcNemx9FJDIpfe/dkLewNAPj0mLrqM3oVBdM g/XNS1aEW03Hzr9OeQ1bS5sACYZVwmJcZu2q7fzhJjjGTJaKv7YKhKOddthjBiFrxESi 79jfwXvGe9/B7LKUQoZwgw+nfavT0uLm5Tjkg= Received: by 10.224.87.75 with SMTP id v11mr2490701qal.236.1254142141345; Mon, 28 Sep 2009 05:49:01 -0700 (PDT) Received: from ?10.134.24.151? (mobile-166-137-135-051.mycingular.net [166.137.135.51]) by mx.google.com with ESMTPS id 6sm1562650qwk.33.2009.09.28.05.48.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 28 Sep 2009 05:49:00 -0700 (PDT) References: <20090928121745.GA19803@annexia.org> Message-Id: From: Yaron Minsky To: Richard Jones In-Reply-To: <20090928121745.GA19803@annexia.org> Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Mailer: iPhone Mail (7C144) Mime-Version: 1.0 (iPhone Mail 7C144) Subject: Re: [Caml-list] xpath or alternatives Date: Mon, 28 Sep 2009 08:48:54 -0400 Cc: "caml-list@inria.fr" X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 subnodes:01 node:01 yaron:01 minsky:01 ocaml:01 frisch:01 frisch:01 beginner's:01 ocaml:01 bug:01 28,:98 beginners:01 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 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