Xml Schema and deriving Haskell2Xml, was Re: haxr - marshalling of Variants in Records

Simon Foster s.d.f at btinternet.com
Mon Dec 5 16:27:59 EST 2005


As Shae says, HAIFA can do XML Schema -> Haskell Mapping (if you can
call it Haskell); well at least it could, I've since done some
refactoring on the XML Serializer class so it won't work out of box, but
should work with some tweaking. I stopped working on it because in order
to map XML Schema properly I needed to break Haskell's type-system in
just about every way possible and the code was quite horrible. In order
to represent Sequences and Choices (the staple part of XML Schema
Complex-Types), you need HList and Union types, since structures within
a single complex-type can be quite ... err ... complex. As a result the
whole thing is undecidable and context stack overflows are not uncommon.
Nevertheless - it does work; it takes an XML Schema and produces a
Haskell module called things like Org.W3.N2001.XMLSchema with
serializers, but the data-types produced are pretty horrible and
undecidable - see the attachment generated from Google Search.
Fortunately as Google Search doesn't use either Sequences(/Interleaving)
or Union types in awkward places the types aren't too bad in this case.

The other problem you're likely to run up against is a lack of automatic
mutual module recursion support for Haskell, assuming you want to map
each schema namespace to a single module - there exists quite a lot of
examples of mutually recursive schemas. Certainly I haven't even
attempted to work round this problem yet.

If I get round to it, I'll try and get XML Schema serialization and
type-mapping work again; although it's pretty non-trivial to use. There
aren't any source distributions of HAIFA atm, though I can easily bring
the darcs repositories back online.

To be honest though, it may be better to do the type-mapping outside of
Haskell (anathema I know, but other languages do already have full
schema support) - this project seems to have made a reasonable start:
http://www.cin.ufpe.br/~haskell/hwsproxygen/, although the mapping they
do seems to be quite primitive at the moment, and even if the data-types
were created outside of Haskell, you'd still have to work out how to
represent Unions/embedded Sequences effectively.

Oh, and so far as XML Serializer derivation goes, HAIFA can do that
quite nicely with a number of xmlify* TH functions. Although I know
other libraries have this too and may do it better.



On Mon, 2005-12-05 at 20:43 +0100, Shae Matijs Erisson wrote:
> Johannes Waldmann <waldmann at imn.htwk-leipzig.de> writes:
> > If the Haskell app is the defining side,
> > I'd love to just "derive Haskell2Xml" for my data,
> > and then I'd want a "haskell2scheme" (not: DTD)
> > so that the Java side can use a Schema->Java compiler (like xjc).
> >
> > On the other hand if I have to use a given XML schema,
> > I want some "xhc" tool (Schema->Haskell).
> >
> > Perhaps some of these projects are already out there?
> See the new XmlContent type/module in HaXml 1.14:
> http://nhc98.blogspot.com/2005/10/unifying-haskell2xml-and-xml2haskell.html
> Relax NG was prototyped in Haskell, not sure if that helps any.
> HAIFA does some sort of Xml Schema work.
> There's an HAIFA article in the first issue of The Monad.Reader:
> http://www.haskell.org/hawiki/TheMonadReader/IssueOne
> --
> Shae Matijs Erisson - http://www.ScannedInAvian.com/ - Sockmonster once said:
> You could switch out the unicycles for badgers, and the game would be the same.
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GoogleSearch1.hs
Type: text/x-haskell
Size: 21172 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/libraries/attachments/20051205/8c61dbcd/GoogleSearch1-0001.bin

More information about the Libraries mailing list