Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] XML output

2 views
Skip to first unread message

Rémi Dewitte

unread,
Mar 17, 2009, 7:02:22 AM3/17/09
to caml-list
Hello,

I have used pxp to parse xml and I am happy with it. I'd like now to produce
xml and wonder what are the options to do so (possibly the simpliest).

I think I am going to start with the Printf module. I wonder how well it
handles utf8 for example. And I'll have to write a kind of xml_encode
function. I am pretty sure it has already be done somewhere !

Many thanks,
Rémi

Gerd Stolpmann

unread,
Mar 17, 2009, 7:53:43 AM3/17/09
to Rémi Dewitte, caml-list

Am Dienstag, den 17.03.2009, 12:01 +0100 schrieb Rémi Dewitte:
> Hello,
>
> I have used pxp to parse xml and I am happy with it. I'd like now to
> produce xml and wonder what are the options to do so (possibly the
> simpliest).

Maybe not the simplest: Use the PXP preprocessor to create the output
tree, and print the tree:

http://projects.camlcity.org/projects/dl/pxp-1.2.1/doc/manual/html/ref/Intro_preprocessor.html
http://projects.camlcity.org/projects/dl/pxp-1.2.1/doc/manual/html/ref/Pxp_document.document.html#2_WritingdocumentsasXMLtext


>
> I think I am going to start with the Printf module. I wonder how well
> it handles utf8 for example.

UTF-8 are just bytes for printf.

> And I'll have to write a kind of xml_encode function. I am pretty sure
> it has already be done somewhere !

let xml_encode =
Netencoding.Html.encode
~in_enc:`Enc_utf8
~out_enc:`Enc_usascii
~prefer_names:false
()

That would assume the input is UTF-8 encoded, and the output is
ASCII-encoded. You can control which ASCII characters get the special
XML representation &...; with the unsafe_chars optional argument.
Docs are at
http://projects.camlcity.org/projects/dl/ocamlnet-2.2.9/doc/html-main/Netencoding.Html.html

Gerd
--
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
ge...@gerd-stolpmann.de http://www.gerd-stolpmann.de
Phone: +49-6151-153855 Fax: +49-6151-997714
------------------------------------------------------------


_______________________________________________
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

Michaël Le Barbier

unread,
Mar 17, 2009, 8:01:08 AM3/17/09
to Rémi Dewitte, caml-list

Le 17 mars 09 à 12:01, Rémi Dewitte a écrit :

I am also very interesting in this question. Besides Gerd's
suggestion, is there a solution that can help writing SGML-ish thingies?

Maybe the Eiom library (part of the OCsigen project) can also interest
you, although I never used it and that it might be focused on HTML.
--
Cheers,
Michaël

Sylvain Le Gall

unread,
Mar 17, 2009, 8:53:51 AM3/17/09
to caml...@inria.fr
On 17-03-2009, Rémi Dewitte <re...@gide.net> wrote:
>
> I think I am going to start with the Printf module. I wonder how well it
> handles utf8 for example. And I'll have to write a kind of xml_encode
> function. I am pretty sure it has already be done somewhere !
>

Maybe it is a bit overkilling, but there is also ocamlduce.

See there:
http://www.cduce.org/ocaml
(dev for ocaml 3.11:)
http://ocamlduce.forge.ocamlcore.org/
http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=ocamlduce/ocamlduce.git;a=summary

OCamlduce can also be used with Eliom/OCsigen.

AFAIK, using ocamlduce can help you to type check your output tree
directly within OCaml compiler...

Regards
Sylvain Le Gall

Matthieu Wipliez

unread,
Mar 17, 2009, 9:02:10 AM3/17/09
to Sylvain Le Gall, caml...@inria.fr

Yet another solution is Xmlm by Daniel Bünzli.

http://erratique.ch/software/xmlm

This is probably the easiest and lightweight solution: Xmlm comes as a single module and its interface, and it's BSD so you can just copy/paste it into your project.

Cheers,
Matthieu

----- Message d'origine ----
> De : Sylvain Le Gall <syl...@le-gall.net>
> À : caml...@inria.fr
> Envoyé le : Mardi, 17 Mars 2009, 13h53mn 30s
> Objet : [Caml-list] Re: XML output

Rémi Dewitte

unread,
Mar 17, 2009, 9:21:08 AM3/17/09
to Matthieu Wipliez, Sylvain Le Gall, caml...@inria.fr
Thanks every one !

I guess I have to pick the one now :)

Rémi

Michael Ekstrand

unread,
Mar 17, 2009, 12:25:49 PM3/17/09
to caml...@inria.fr
Matthieu Wipliez <mwip...@yahoo.fr> writes:
> Yet another solution is Xmlm by Daniel Bünzli.
>
> http://erratique.ch/software/xmlm
>
> This is probably the easiest and lightweight solution: Xmlm comes as a
> single module and its interface, and it's BSD so you can just
> copy/paste it into your project.

I second the xmlm suggestion. Polling event-based parsing is very slick
and maps well into the functional paradigm, and its XML writing support
(generating a stream of events identical to those you read) makes
generation quite intuitive and reliable.

- Michael

--
mouse, n: A device for pointing at the xterm in which you want to type.
Confused by the strange files? I cryptographically sign my messages.
For more information see <http://www.elehack.net/resources/gpg>.

0 new messages