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 <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:String>, String <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:String>)] introspectData a = zip <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:zip> fields (gmapQ gshow a) where fields = constrFields $ <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.> toConstr a -- function to create xml string from single-layer Haskell data type serializeXml object = "<" ++ <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.> show <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:show>(toConstr object) ++ <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.> ">" ++ <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.> foldr <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:foldr> (\(a,b) x -> x ++ <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.> "<" ++ a ++ ">" ++ b ++ "</" ++ a ++ ">") "" ( introspectData object ) ++ <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.> "</" ++ <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.> show <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:show>(toConstr object) ++ <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:.> ">" ... however cant figure out how to go the other way. Usage of haxml or HXT to achieve this is ok, whatever it takes ;-)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe