-- root element \<message\> that contains an entire news item.
--
module TSN.XML.News (
- Message,
- news_tests )
+ news_tests,
+ pickle_message )
where
import Data.Data ( Data, constrFields, dataTypeConstrs, dataTypeOf )
import Test.Tasty.HUnit ( (@?=), testCase )
import Text.XML.HXT.Core (
PU,
- XmlPickler(..),
xp13Tuple,
xpAttr,
xpElem,
xml_mid :: MsgId,
xml_category :: String,
xml_sport :: String,
- xml_url :: String,
+ xml_url :: Maybe String,
xml_teams :: [NewsTeam],
xml_locations :: [NewsLocation],
xml_sms :: String,
News {
db_mid :: MsgId,
db_sport :: String,
- db_url :: String,
+ db_url :: Maybe String,
db_sms :: String,
db_editor :: Maybe String,
db_text :: Maybe String,
from_string :: String -> NewsTeam
from_string = NewsTeam
-instance XmlPickler NewsTeam where
- xpickle = pickle_news_team
pickle_msg_id :: PU MsgId
pickle_msg_id =
from_tuple = uncurryN MsgId
to_tuple m = (db_msg_id m, db_event_id m)
-instance XmlPickler MsgId where
- xpickle = pickle_msg_id
pickle_location :: PU NewsLocation
pickle_location =
uncurryN NewsLocation
to_tuple l = (city l, state l, country l)
-instance XmlPickler NewsLocation where
- xpickle = pickle_location
pickle_message :: PU Message
pickle_msg_id
(xpElem "category" xpText)
(xpElem "sport" xpText)
- (xpElem "url" xpText)
+ (xpElem "url" $ xpOption xpText)
(xpList pickle_news_team)
(xpList pickle_location)
(xpElem "SMS" xpText)
to_string :: [String] -> String
to_string = join "\n"
-instance XmlPickler Message where
- xpickle = pickle_message
-
-- * Tasty Tests