X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FGameInfo.hs;h=af622f0cae84926a79871e0053ec25bc43ec88c8;hb=1a8faeb14fad864bc760abbfef385f65868aa21d;hp=b3ac3f6e51a844fbc4f4261f38d0af7d15f8ae2b;hpb=544048a56449348167a5a0c2c339de03c1e2abc2;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/GameInfo.hs b/src/TSN/XML/GameInfo.hs index b3ac3f6..af622f0 100644 --- a/src/TSN/XML/GameInfo.hs +++ b/src/TSN/XML/GameInfo.hs @@ -5,9 +5,19 @@ -- See also: TSN.XML.SportInfo -- module TSN.XML.GameInfo ( - dtds ) + dtds, + from_xml ) where +import Data.Time.Clock ( UTCTime ) +import Text.XML.HXT.Core ( XmlTree ) +import Text.XML.HXT.DOM.ShowXml ( xshow ) + +import TSN.Parse ( + parse_message, + parse_xmlfid, + parse_xml_time_stamp ) + -- | The DTDs for everything that we consider "Game Info." -- -- TODO: This is the list from the old implementation. We need to @@ -37,3 +47,24 @@ dtds = "nhlpreviewxml.dtd", "recapxml.dtd", "WorldBaseballPreviewXML.dtd" ] + + +-- | The data structure that holds the XML representation of a +-- GameInfo message. +-- +data Message = + Message { + dtd :: String, + xml_file_id :: Int, + time_stamp :: UTCTime, + xml :: String } + deriving (Eq, Show) + + +from_xml :: String -> XmlTree -> Either String Message +from_xml dtdname xmltree = do + xmlfid <- parse_xmlfid xmltree + timestamp <- parse_xml_time_stamp xmltree + message <- parse_message xmltree + return $ Message dtdname (fromInteger xmlfid) timestamp (xshow [message]) +