]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/TSN/Location.hs
Move pickle_location into the TSN.Location module and update TSN.XML.News.
[dead/htsn-import.git] / src / TSN / Location.hs
index 1097d933f004cb952af5a0a1fc17b60161bc9f8f..178c6c5b4417c46db5894bed56b0a3db16ba9dea 100644 (file)
 --
 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)