Version française
Home     About     Download     Resources     Contact us    
Browse thread
xmlm and names(paces)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bünzli_Daniel <daniel.buenzli@e...>
Subject: Re: [Caml-list] xmlm and names(paces)

Le 6 févr. 08 à 23:56, Bünzli Daniel a écrit :

>  Of course this means more work for the client, but it makes the  
> basic interface simpler and it allows the client
> to use variants instead of simply shorter prefixes.

Now that I think of it instead of (what I have now) :

> type name = string * string
> type attribute = name * string
> type tag = name * attribute list
>
> val input : ?enc:encoding option -> ?strip:bool ->
>    ?ns: (string -> string option) ->
>    ?entity: (string -> string option) ->
>    ?prolog: (dtd -> unit) ->
>    ?prune:(tag -> 'a -> bool) ->
>    ?s:(tag -> 'a -> 'a) ->	
>    ?e:(tag -> 'a -> 'a) ->
>    ?d:(string -> 'a -> 'a)  -> 'a -> input ->
>      [ `Value of 'a | `Error of (int * int) * error ]

(~s is for start tag, ~e is for end tag (the full start tag is given  
again), ~d is for data)

Why not have a callback ~name which is given the expanded name  
(uri,local) allows the client to do whathever it wishes and
a callback ~att to build attributes :

> val input : ?enc:encoding option -> ?strip:bool ->
>    ?ns: (string -> string option) ->
>    ?entity: (string -> string option) ->
>    name: (string -> string -> 'n) ->
>    att: ('n -> string -> 'att)
>    ?prolog: (dtd -> unit) ->
>    ?prune:('n * 'att -> 'a -> bool) ->
>    ?s:('n * 'att list -> 'a -> 'a) ->	
>    ?e:('n * 'att list -> 'a -> 'a) ->
>    ?d:(string -> 'a -> 'a)  -> 'a -> input ->
>      [ `Value of 'a | `Error of (int * int) * error ]


This allows you to give precise variant cases for the things your  
process and have a catch all case for what you are not interested in.   
Output would be polymorphised accordingly and the client provides  
inverses of ~name ('n -> string * string) and ~att ('att -> 'n *  
string).

On the other hand the work performed by ~name and ~att can be done by  
the client in ~s or ~e. The only thing the latter solution brings is  
to avoid folding over the tag type if you want to transform it. So  
finally I don't think it is worth it (especially because the  
polymorphised output feels cumbersome).

Any comment ?

Daniel