{-# LANGUAGE TypeOperators #-} {- Example by Sjoerd Visscher -} module XMLExample where import XMLRep import Generics.MultiRec.Elems.Many import Generics.MultiRec.GMap import Generics.MultiRec.Eq import Generics.MultiRec.FoldAlgK import qualified Generics.MultiRec.Show as GS import qualified Generics.MultiRec.ZipWith as Z example :: Node String String example = Elt "test" [] [ Elt "hoi" [Attr "href" "w3future.com"] [] , Text " bla " , Elt "doei" [] [] ] addPrefix :: Node String String -> Node String String addPrefix = gmap (apply $ ("x:" ++) & id) Node Node normalizeSpace :: Node String String -> Node String String normalizeSpace = gmap (apply $ id & (unwords . words)) Node Node serializeAlg :: Algebra XML (String :|: String :|: Nil) String serializeAlg _ = ( (\name attrs children -> "<" ++ name ++ attrs ++ ">" ++ children ++ "") & (\value -> value) ) & (\name value -> " " ++ name ++ "=\"" ++ value ++ "\"") & ( "" & (++) ) & ( "" & (++) ) serialize :: Node String String -> String serialize = fold serializeAlg Node