Text.XML.HaXml.Haskell2Xml is a library for translating Haskell data from any program into a valid XML document (and back again), by generating a DTD and the appropriate functions to write and write the XML format. In principle, it gives an alternative to the standard Read and Show classes, and allows you to use other standard XML-processing tools on your Haskell datafiles.
Usage. It works rather like the existing Read and Show classes: you must create an instance of the Haskell2Xml class for every datatype you wish to use for I/O. However, because this class is not a standard one, no Haskell compilers support the deriving clause for it yet. Fear not! There is a pre-processor tool called DrIFT which derives class instances automatically. We have extended DrIFT's ruleset to include the Haskell2Xml class. The only remaining thing is to ensure that you import the Text.XML.HaXml.Haskell2Xml module everywhere you use it.
(Please note that DrIFT is sometimes a bit fragile when parsing Haskell sources - it occasionally fails to recognise the derive command. We have found a workaround: isolate just the data type declarations that are of interest, and run DrIFT on them separately.)
To read and write Haskell data values as XML files, use the functions
Haskell2Xml.readXml :: XmlContent a => FilePath -> IO a Haskell2Xml.writeXml :: XmlContent a => FilePath -> a -> IO ()not forgetting to resolve the overloading in one of the usual ways (e.g. by implicit context at point of use, by explicit type signatures on values, use value as an argument to a function with an explicit signature, use `asTypeOf`, etc.)