Created
April 11, 2018 16:30
-
-
Save k0001/e48b330fc09267f8890ef67f3361f879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE OverloadedLists #-} | |
module Main where | |
import qualified Data.ByteString as BS | |
import Data.HashMap.Strict (HashMap) | |
import Data.Text (Text) | |
import qualified Xmlbf as X | |
import qualified Xmlbf.Xeno as Xx | |
data AtomFeed = AtomFeed | |
{ feedName :: !Text | |
, feedAttrs :: !(HashMap Text Text) | |
, feedChildren :: ![X.Node] | |
} deriving (Show, Eq) | |
instance X.ToXml AtomFeed where | |
toXml = \(AtomFeed n as cs) -> | |
let title = X.element' "atom:title" [] [X.text n] | |
in [X.element' "atom:feed" as (title : cs)] | |
instance X.FromXml AtomFeed where | |
fromXml = X.pElement "atom:feed" $ do | |
title <- X.pElement "atom:title" X.pText | |
attrs <- X.pAttrs | |
pure (AtomFeed title attrs []) | |
rawFeed :: BS.ByteString | |
rawFeed = | |
"<atom:feed xmlns:atom=\"http://www.w3.org/2005/Atom\">\ | |
\ <atom:title>ServicePlan Feed</atom:title>\ | |
\</atom:feed>" | |
expectedFeed :: AtomFeed | |
expectedFeed = AtomFeed | |
{ feedName = "ServicePlan Feed" | |
, feedAttrs = [("xmlns:atom", "http://www.w3.org/2005/Atom")] | |
, feedChildren = [] | |
} | |
actualFeed :: AtomFeed | |
Right actualFeed = X.runParser X.fromXml =<< Xx.nodes rawFeed | |
Author
k0001
commented
Apr 11, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment