]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/Main.hs
Comment out the DTD in Injuries_Detail_XML.xml.
[dead/htsn-import.git] / src / Main.hs
index d2e51727f9468b58417c0ecbb7ba71cdefeef324..2ca3a83816843db631ed6a5eef56366384b4c242 100644 (file)
@@ -1,18 +1,60 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE OverloadedStrings #-}
+
 module Main
 where
 
+--import Control.Monad.IO.Class  ( liftIO )
+import Data.Maybe ( listToMaybe )
+--import Database.Groundhog.TH
+--import Database.Groundhog.Sqlite
 import Text.Show.Pretty ( ppShow )
-import Text.XML.HXT.Core
+import Text.XML.HXT.Core (
+  SysConfigList,
+  XmlPickler,
+  no,
+  runX,
+  withPreserveComment,
+  withRemoveWS,
+  withValidate,
+  xpickle,
+  xunpickleDocument,
+  yes )
+
+import qualified TSN.Injuries as Injuries ( Message )
+import qualified TSN.InjuriesDetail as InjuriesDetail ( Message )
+
+parse_opts :: SysConfigList
+parse_opts =
+  [ withPreserveComment no,
+    withRemoveWS yes,
+    withValidate no ]
 
-import qualified TSN.Injuries as Injuries
+parse_file :: XmlPickler a => FilePath -> IO (Maybe a)
+parse_file path =
+  fmap listToMaybe $
+    runX ( xunpickleDocument xpickle parse_opts path )
 
+-- main_sql :: IO ()
+-- main_sql =
+--   withSqliteConn "foo.sqlite3" $ runDbConn $ do
+--   runMigration defaultMigrationLogger $ do
+--     migrate (undefined :: Injuries.Message)
+--     migrate (undefined :: Injuries.Listing)
+
+--   msg :: Maybe Injuries.Message <- liftIO $ parse_file
+--                                                "test/xml/injuriesxml.xml"
+--   case msg of
+--     Nothing -> return ()
+--     Just m  -> do
+--       msg_id <- insert m
+--       return ()
 
 main :: IO ()
 main = do
-  res <- runX ( xunpickleDocument Injuries.pickle_message
-                       [ withValidate no
-                       , withTrace 1
-                       , withRemoveWS yes
-                       , withPreserveComment no
-                       ] "test/xml/injuriesxml.xml" )
-  putStr $ ppShow res
+  msg1 :: Maybe Injuries.Message <- parse_file "test/xml/injuriesxml.xml"
+  putStr $ ppShow msg1
+
+  msg2 :: Maybe InjuriesDetail.Message <- parse_file
+                                            "test/xml/Injuries_Detail_XML.xml"
+  putStr $ ppShow msg2