1 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE QuasiQuotes #-}
4 {-# LANGUAGE StandaloneDeriving #-}
5 {-# LANGUAGE TemplateHaskell #-}
6 {-# LANGUAGE TypeFamilies #-}
8 -- | Parse TSN XML for the DTD "injuriesxml.dtd". Each document
9 -- contains a root element \<message\> that in turn contains zero or
12 -- The listings will be mapped to a database table called "injuries"
13 -- automatically. The root message is not retained.
20 import Data.Tuple.Curry ( uncurryN )
21 import Database.Groundhog()
22 import Database.Groundhog.TH
23 import Text.XML.HXT.Core (
49 listings :: [Listing],
50 time_stamp :: String }
54 mkPersist defaultCodegenConfig [groundhog|
60 pickle_listing :: PU Listing
63 xpWrap (from_tuple, to_tuple) $
64 xp4Tuple (xpElem "team" xpText)
65 (xpElem "teamno" xpPrim)
66 (xpElem "injuries" xpText)
67 (xpElem "updated" xpPrim)
69 from_tuple = uncurryN Listing
70 to_tuple l = (team l, teamno l, injuries l, updated l)
72 instance XmlPickler Listing where
73 xpickle = pickle_listing
76 pickle_message :: PU Message
79 xpWrap (from_tuple, to_tuple) $
80 xp6Tuple (xpElem "XML_File_ID" xpPrim)
81 (xpElem "heading" xpText)
82 (xpElem "category" xpText)
83 (xpElem "sport" xpText)
84 (xpList pickle_listing)
85 (xpElem "time_stamp" xpText)
87 from_tuple = uncurryN Message
88 to_tuple m = (xml_file_id m,
95 instance XmlPickler Message where
96 xpickle = pickle_message