X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FLocation.hs;h=178c6c5b4417c46db5894bed56b0a3db16ba9dea;hb=83bad08d7f28143cdaae42156d951b421fa15a8a;hp=1097d933f004cb952af5a0a1fc17b60161bc9f8f;hpb=e96fc68293b6ac51eb0e8a4fe9ac9afa515cca83;p=dead%2Fhtsn-import.git diff --git a/src/TSN/Location.hs b/src/TSN/Location.hs index 1097d93..178c6c5 100644 --- a/src/TSN/Location.hs +++ b/src/TSN/Location.hs @@ -14,15 +14,25 @@ -- module TSN.Location ( Location(..), + pickle_location, + -- * WARNING: these are private but exported to silence warnings LocationConstructor(..) ) where -- System imports +import Data.Tuple.Curry ( uncurryN ) import Database.Groundhog () -- Required for some String instance import Database.Groundhog.TH ( defaultCodegenConfig, groundhog, mkPersist ) +import Text.XML.HXT.Core ( + PU, + xpElem, + xpOption, + xpText, + xpTriple, + xpWrap ) -- | Database representation of a location. @@ -52,3 +62,19 @@ mkPersist defaultCodegenConfig [groundhog| type: constraint fields: [city, state, country] |] + + + +-- | We also provide an (un)pickler for one common XML representation, +-- used at least in "TSN.XML.News" and "TSN.XML.Location". +-- +pickle_location :: PU Location +pickle_location = + xpElem "location" $ + xpWrap (from_tuple, to_tuple) $ + xpTriple (xpOption (xpElem "city" xpText)) + (xpOption (xpElem "state" xpText)) + (xpElem "country" xpText) + where + from_tuple = uncurryN Location + to_tuple l = (city l, state l, country l)