Hi,

Trying to write a function to deserialize a haskell type from xml.

Ideally this wont need a third "DTD" file, ie it will work something like XmlSerializer.Deserialize from C#:

deserializeXml :: Data(a) => String -> a
serializeXml :: Data(a) => a -> String

Writing serializeXml is pretty easy:
import Data.Generics
-- helper function from http://www.defmacro.org/ramblings/haskell-web.html
introspectData :: Data a => a -> [( String, String)]
introspectData a = zip fields (gmapQ gshow a)
where fields = constrFields $ toConstr a
 
-- function to create xml string from single-layer Haskell data type
serializeXml object = "<" ++ show(toConstr object ) ++ ">" ++
foldr (\(a,b) x -> x ++ "<" ++ a ++ ">" ++ b ++ "</" ++ a ++ ">") "" ( introspectData object )
++ "</" ++ show(toConstr object) ++ ">"

... however cant figure out how to go the other way.

Usage of haxml or HXT to achieve this is ok, whatever it takes ;-)