[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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 |
If I am not mistaken you are selecting a domain whose first child is a
device node whose only child is disk node ...
instead of:
<domain..>[<devices..>[<disk..>[<source dev=(Latin1 & s) ..>_]]]
you should aim for something in the vein of:
<domain ..> [_* (<devices..> (<disk..>(<source dev=(Latin1 & s)>|
<souce file = (Latin1 &s)>_)* |_)* _*]
Till
On Wed, Sep 30, 2009 at 10:01 AM, Richard Jones <rich@annexia.org> wrote:
> On Wed, Sep 30, 2009 at 09:33:07AM -0400, Till Varoquaux wrote:
>> OCamlduce (Alain correct me if I am wrong) basically maintains two
>> separate type systems side by side (the Xduce one and the Ocaml one).
>> This is done in order to make Ocamlduce maintainable by keeping a
>> clear separation. As a result you have to explicitly convert values
>> between type systems using {:...:}. These casts are type safe but do
>> lead to some work at runtime.
>>
>> Also note that ocaml's string are Latin1 and not String in the XML world. So:
>>
>> Â let devs = match xml with
>> Â Â | {{ <domain>[<devices>[<source dev=(Latin1 & dev) ..>[]]] }} -> {:dev:}
>> Â Â | {{ <domain>[<devices>[<source file=(Latin1 & file) ..>[]]] }} ->
>> {:file:} in
>>
>> Should work (I'm rusty and have nothing to check handy).
>
> I tried variations on the above, but couldn't get it to work.
> ocamlduce is very fond of a mysterious error called "Error: Subtyping
> failed", which is very difficult for me to understand, and therefore
> must be absolutely impossible for someone not used to strong typing.
>
> This is where I'm heading at the moment (sorry, my previous
> example missed a <disk> level inside <devices>), so:
>
> Â let xml = from_string xml in
> Â prerr_endline (Ocamlduce.to_string xml);
>
> Â let devs = {{ map [xml] with
> Â Â | <domain..>[<devices..>[<disk..>[<source dev=(Latin1 & s) ..>_]]]
> Â Â | <domain..>[<devices..>[<disk..>[<source file=(Latin1 & s) ..>_]]] -> [s]
> Â Â | _ -> [] }} in
> Â prerr_endline (Ocamlduce.to_string devs);
>
> +1 : this compiles
> -1 : it doesn't work, devs is empty
>
> This is what the first prerr_endline prints:
>
> <domain
> Â type="kvm"
> Â id="2">[
> Â <name>[ 'CentOS5x32' ]
> Â <uuid>[ '2ce397d9-1931-feb1-8ad8-15f22c4f18af' ]
> Â <memory>[ '524288' ]
> Â <currentMemory>[ '524288' ]
> Â <vcpu>[ '1' ]
> Â <os>[ <type arch="x86_64" machine="pc-0.11">[ 'hvm' ] <boot dev="hd">[ ] ]
> Â <features>[ <acpi>[ ] <apic>[ ] <pae>[ ] ]
> Â <clock offset="utc">[ ]
> Â <on_poweroff>[ 'destroy' ]
> Â <on_reboot>[ 'restart' ]
> Â <on_crash>[ 'restart' ]
> Â <devices>[
> Â Â <emulator>[ '/usr/bin/qemu-kvm' ]
> Â Â <disk
> Â Â Â type="block"
> Â Â Â device="disk">[
> Â Â Â <source dev="/dev/vg_trick/CentOS5x32">[ ]
> Â Â Â <target bus="ide" dev="hda">[ ]
> Â Â Â ]
> Â Â <interface
> Â Â Â type="network">[
> Â Â Â <mac address="54:52:00:3c:76:11">[ ]
> Â Â Â <source network="default">[ ]
> Â Â Â <target dev="vnet0">[ ]
> Â Â Â ]
> Â Â <serial type="pty">[ <source path="/dev/pts/7">[ ] <target port="0">[ ] ]
> Â Â <console
> Â Â Â type="pty"
> Â Â Â tty="/dev/pts/7">[
> Â Â Â <source path="/dev/pts/7">[ ]
> Â Â Â <target port="0">[ ]
> Â Â Â ]
> Â Â <input type="mouse" bus="ps2">[ ]
> Â Â <graphics autoport="yes" port="5900" type="vnc">[ ]
> Â Â <video>[ <model type="cirrus" vram="9216" heads="1">[ ] ]
> Â Â ]
> Â ]
>
> and what the second prerr_endline prints:
>
> ""
>
> Rich.
>
> --
> 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
>