    --------------------------------------------------------------------
    -- |
    -- Module    : Text.RSS1.Export
    -- Copyright : (c) Galois, Inc. 2008,
    --             (c) Sigbjorn Finne 2009-
    -- License   : BSD3
    --
    -- Maintainer: Sigbjorn Finne <sof@forkIO.com>
    -- Stability : provisional
    -- Portability: portable
    --
    --------------------------------------------------------------------
    module Text.RSS1.Export
      ( xmlFeed
      , textFeed
      ) where

    import Prelude.Compat

    import Text.DublinCore.Types
    import Text.RSS1.Syntax
    import Text.RSS1.Utils
    import qualified Data.Text.Util as U

    import Data.List.Compat
    import Data.Text (Text)
    import qualified Data.Text as T
    import qualified Data.Text.Lazy as TL
    import Data.XML.Compat
    import Data.XML.Types as XML

    qualNode :: (Maybe Text, Maybe Text) -> Text -> [XML.Node] -> XML.Element
    qualNode :: (Maybe Text, Maybe Text) -> Text -> [Node] -> Element
    qualNode ns :: (Maybe Text, Maybe Text)
    ns n :: Text
    n cs :: [Node]
    cs = Element :: Name -> [(Name, [Content])] -> [Node] -> Element
    Element {elementName :: Name
    elementName = (Maybe Text, Maybe Text) -> Text -> Name
    qualName (Maybe Text, Maybe Text)
    ns Text
    n, elementAttributes :: [(Name, [Content])]
    elementAttributes = [], elementNodes :: [Node]
    elementNodes = [Node]
    cs}

    qualNode' :: (Text, Text) -> Text -> [XML.Node] -> XML.Element
    qualNode' :: (Text, Text) -> Text -> [Node] -> Element
    qualNode' (uri :: Text
    uri, pre :: Text
    pre) = (Maybe Text, Maybe Text) -> Text -> [Node] -> Element
    qualNode (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    uri, Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    pre)

    ---
    xmlFeed :: Feed -> XML.Element
    xmlFeed :: Feed -> Element
    xmlFeed f :: Feed
    f =
      ((Text, Text) -> Text -> [Node] -> Element
    qualNode' (Text
    rdfNS, Text
    rdfPrefix) "RDF" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map
         Element -> Node
    NodeElement
         ([[Element]] -> [Element]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat
            [ [Channel -> Element
    xmlChannel (Feed -> Channel
    feedChannel Feed
    f)]
            , (Image -> Element) -> Maybe Image -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Image -> Element
    xmlImage (Feed -> Maybe Image
    feedImage Feed
    f)
            , (Item -> Element) -> [Item] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Item -> Element
    xmlItem (Feed -> [Item]
    feedItems Feed
    f)
            , (TextInputInfo -> Element) -> Maybe TextInputInfo -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb TextInputInfo -> Element
    xmlTextInput (Feed -> Maybe TextInputInfo
    feedTextInput Feed
    f)
            , (TaxonomyTopic -> Element) -> [TaxonomyTopic] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map TaxonomyTopic -> Element
    xmlTopic (Feed -> [TaxonomyTopic]
    feedTopics Feed
    f)
            , Feed -> [Element]
    feedOther Feed
    f
            ]))
            -- should we expect these to be derived by the XML pretty printer..?
        { elementAttributes :: [(Name, [Content])]
    elementAttributes =
            [(Name, [Content])] -> [(Name, [Content])]
    forall a. Eq a => [a] -> [a]
    nub ([(Name, [Content])] -> [(Name, [Content])])
    -> [(Name, [Content])] -> [(Name, [Content])]
    forall a b. (a -> b) -> a -> b
    $
            Name -> Text -> (Name, [Content])
    mkNAttr ((Maybe Text, Maybe Text) -> Text -> Name
    qualName (Maybe Text
    forall a. Maybe a
    Nothing, Maybe Text
    forall a. Maybe a
    Nothing) "xmlns") Text
    rss10NS (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    :
            Name -> Text -> (Name, [Content])
    mkNAttr ((Maybe Text, Maybe Text) -> Text -> Name
    qualName (Maybe Text
    forall a. Maybe a
    Nothing, Text -> Maybe Text
    forall a. a -> Maybe a
    Just "xmlns") Text
    rdfPrefix) Text
    rdfNS (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    :
            Name -> Text -> (Name, [Content])
    mkNAttr ((Maybe Text, Maybe Text) -> Text -> Name
    qualName (Maybe Text
    forall a. Maybe a
    Nothing, Text -> Maybe Text
    forall a. a -> Maybe a
    Just "xmlns") Text
    synPrefix) Text
    synNS (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    :
            Name -> Text -> (Name, [Content])
    mkNAttr ((Maybe Text, Maybe Text) -> Text -> Name
    qualName (Maybe Text
    forall a. Maybe a
    Nothing, Text -> Maybe Text
    forall a. a -> Maybe a
    Just "xmlns") Text
    taxPrefix) Text
    taxNS (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    :
            Name -> Text -> (Name, [Content])
    mkNAttr ((Maybe Text, Maybe Text) -> Text -> Name
    qualName (Maybe Text
    forall a. Maybe a
    Nothing, Text -> Maybe Text
    forall a. a -> Maybe a
    Just "xmlns") Text
    conPrefix) Text
    conNS (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    :
            Name -> Text -> (Name, [Content])
    mkNAttr ((Maybe Text, Maybe Text) -> Text -> Name
    qualName (Maybe Text
    forall a. Maybe a
    Nothing, Text -> Maybe Text
    forall a. a -> Maybe a
    Just "xmlns") Text
    dcPrefix) Text
    dcNS (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    : Feed -> [(Name, [Content])]
    feedAttrs Feed
    f
        }

    textFeed :: Feed -> Maybe TL.Text
    textFeed :: Feed -> Maybe Text
    textFeed = (Feed -> Element) -> Feed -> Maybe Text
    forall a. (a -> Element) -> a -> Maybe Text
    U.renderFeed Feed -> Element
    xmlFeed

    xmlChannel :: Channel -> XML.Element
    xmlChannel :: Channel -> Element
    xmlChannel ch :: Channel
    ch =
      ((Maybe Text, Maybe Text) -> Text -> [Node] -> Element
    qualNode (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "channel" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map
         Element -> Node
    NodeElement
         ([ (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "title" (Channel -> Text
    channelTitle Channel
    ch)
          , (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "link" (Channel -> Text
    channelLink Channel
    ch)
          , (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "description" (Channel -> Text
    channelDesc Channel
    ch)
          ] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlTextInputURI (Channel -> Maybe Text
    channelTextInputURI Channel
    ch) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlImageURI (Channel -> Maybe Text
    channelImageURI Channel
    ch) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          [Text] -> [Element]
    xmlItemURIs (Channel -> [Text]
    channelItemURIs Channel
    ch) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          (DCItem -> Element) -> [DCItem] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map DCItem -> Element
    xmlDC (Channel -> [DCItem]
    channelDC Channel
    ch) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          [[Element]] -> [Element]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat
            [ (UpdatePeriod -> Element) -> Maybe UpdatePeriod -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb UpdatePeriod -> Element
    xmlUpdatePeriod (Channel -> Maybe UpdatePeriod
    channelUpdatePeriod Channel
    ch)
            , (Integer -> Element) -> Maybe Integer -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Integer -> Element
    xmlUpdateFreq (Channel -> Maybe Integer
    channelUpdateFreq Channel
    ch)
            , (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb ((Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    synNS, Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    synPrefix) "updateBase") (Channel -> Maybe Text
    channelUpdateBase Channel
    ch)
            ] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          [ContentInfo] -> [Element]
    xmlContentItems (Channel -> [ContentInfo]
    channelContent Channel
    ch) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ [Text] -> [Element]
    xmlTopics (Channel -> [Text]
    channelTopics Channel
    ch) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ Channel -> [Element]
    channelOther Channel
    ch))
        { elementAttributes :: [(Name, [Content])]
    elementAttributes =
            Name -> Text -> (Name, [Content])
    mkNAttr ((Text, Text) -> Text -> Name
    qualName' (Text
    rdfNS, Text
    rdfPrefix) "about") (Channel -> Text
    channelURI Channel
    ch) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    : Channel -> [(Name, [Content])]
    channelAttrs Channel
    ch
        }

    xmlImageURI :: URIString -> XML.Element
    xmlImageURI :: Text -> Element
    xmlImageURI u :: Text
    u = (Text, Maybe Text) -> Text -> [(Name, [Content])] -> Element
    xmlEmpty (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "image" [Name -> Text -> (Name, [Content])
    mkNAttr (Text -> Name
    rdfName "resource") Text
    u]

    xmlImage :: Image -> XML.Element
    xmlImage :: Image -> Element
    xmlImage i :: Image
    i =
      ((Maybe Text, Maybe Text) -> Text -> [Node] -> Element
    qualNode (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "image" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map
         Element -> Node
    NodeElement
         ([ (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "title" (Image -> Text
    imageTitle Image
    i)
          , (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "url" (Image -> Text
    imageURL Image
    i)
          , (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "link" (Image -> Text
    imageLink Image
    i)
          ] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          (DCItem -> Element) -> [DCItem] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map DCItem -> Element
    xmlDC (Image -> [DCItem]
    imageDC Image
    i) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ Image -> [Element]
    imageOther Image
    i))
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = Name -> Text -> (Name, [Content])
    mkNAttr ((Text, Text) -> Text -> Name
    qualName' (Text
    rdfNS, Text
    rdfPrefix) "about") (Image -> Text
    imageURI Image
    i) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    : Image -> [(Name, [Content])]
    imageAttrs Image
    i}

    xmlItemURIs :: [URIString] -> [XML.Element]
    xmlItemURIs :: [Text] -> [Element]
    xmlItemURIs [] = []
    xmlItemURIs xs :: [Text]
    xs =
      [ (Maybe Text, Maybe Text) -> Text -> [Node] -> Element
    qualNode
          (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing)
          "items"
          [Element -> Node
    NodeElement ((Text, Text) -> Text -> [Node] -> Element
    qualNode' (Text
    rdfNS, Text
    rdfPrefix) "Seq" ((Text -> Node) -> [Text] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Node
    toRes [Text]
    xs))]
      ]
      where
        toRes :: Text -> Node
    toRes u :: Text
    u = Element -> Node
    NodeElement ((Text, Maybe Text) -> Text -> [(Name, [Content])] -> Element
    xmlEmpty (Text
    rdfNS, Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rdfPrefix) "li" [Name -> Text -> (Name, [Content])
    mkNAttr (Text -> Name
    rdfName "resource") Text
    u])

    xmlTextInputURI :: URIString -> XML.Element
    xmlTextInputURI :: Text -> Element
    xmlTextInputURI u :: Text
    u = (Text, Maybe Text) -> Text -> [(Name, [Content])] -> Element
    xmlEmpty (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "textinput" [Name -> Text -> (Name, [Content])
    mkNAttr (Text -> Name
    rdfName "resource") Text
    u]

    xmlTextInput :: TextInputInfo -> XML.Element
    xmlTextInput :: TextInputInfo -> Element
    xmlTextInput ti :: TextInputInfo
    ti =
      ((Maybe Text, Maybe Text) -> Text -> [Node] -> Element
    qualNode (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "textinput" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map Element -> Node
    NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
    forall a b. (a -> b) -> a -> b
    $
       [ (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "title" (TextInputInfo -> Text
    textInputTitle TextInputInfo
    ti)
       , (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "description" (TextInputInfo -> Text
    textInputDesc TextInputInfo
    ti)
       , (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "name" (TextInputInfo -> Text
    textInputName TextInputInfo
    ti)
       , (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "link" (TextInputInfo -> Text
    textInputLink TextInputInfo
    ti)
       ] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (DCItem -> Element) -> [DCItem] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map DCItem -> Element
    xmlDC (TextInputInfo -> [DCItem]
    textInputDC TextInputInfo
    ti) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ TextInputInfo -> [Element]
    textInputOther TextInputInfo
    ti)
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = Name -> Text -> (Name, [Content])
    mkNAttr (Text -> Name
    rdfName "about") (TextInputInfo -> Text
    textInputURI TextInputInfo
    ti) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    : TextInputInfo -> [(Name, [Content])]
    textInputAttrs TextInputInfo
    ti}

    xmlDC :: DCItem -> XML.Element
    xmlDC :: DCItem -> Element
    xmlDC dc :: DCItem
    dc = (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    dcNS, Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    dcPrefix) (DCInfo -> Text
    infoToTag (DCItem -> DCInfo
    dcElt DCItem
    dc)) (DCItem -> Text
    dcText DCItem
    dc)

    xmlUpdatePeriod :: UpdatePeriod -> XML.Element
    xmlUpdatePeriod :: UpdatePeriod -> Element
    xmlUpdatePeriod u :: UpdatePeriod
    u = (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    synNS, Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    synPrefix) "updatePeriod" (UpdatePeriod -> Text
    forall p. IsString p => UpdatePeriod -> p
    toStr UpdatePeriod
    u)
      where
        toStr :: UpdatePeriod -> p
    toStr ux :: UpdatePeriod
    ux =
          case UpdatePeriod
    ux of
            Update_Hourly -> "hourly"
            Update_Daily -> "daily"
            Update_Weekly -> "weekly"
            Update_Monthly -> "monthly"
            Update_Yearly -> "yearly"

    xmlUpdateFreq :: Integer -> XML.Element
    xmlUpdateFreq :: Integer -> Element
    xmlUpdateFreq f :: Integer
    f = (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    synNS, Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    synPrefix) "updateFrequency" (String -> Text
    T.pack (String -> Text) -> String -> Text
    forall a b. (a -> b) -> a -> b
    $ Integer -> String
    forall a. Show a => a -> String
    show Integer
    f)

    xmlContentItems :: [ContentInfo] -> [XML.Element]
    xmlContentItems :: [ContentInfo] -> [Element]
    xmlContentItems [] = []
    xmlContentItems xs :: [ContentInfo]
    xs =
      [ (Text, Text) -> Text -> [Node] -> Element
    qualNode'
          (Text
    conNS, Text
    conPrefix)
          "items"
          [ Element -> Node
    NodeElement (Element -> Node) -> Element -> Node
    forall a b. (a -> b) -> a -> b
    $
            (Text, Text) -> Text -> [Node] -> Element
    qualNode'
              (Text
    rdfNS, Text
    rdfPrefix)
              "Bag"
              ((ContentInfo -> Node) -> [ContentInfo] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map
                 (\e :: ContentInfo
    e -> Element -> Node
    NodeElement ((Text, Text) -> Text -> [Node] -> Element
    qualNode' (Text
    rdfNS, Text
    rdfPrefix) "li" [Element -> Node
    NodeElement (ContentInfo -> Element
    xmlContentInfo ContentInfo
    e)]))
                 [ContentInfo]
    xs)
          ]
      ]

    xmlContentInfo :: ContentInfo -> XML.Element
    xmlContentInfo :: ContentInfo -> Element
    xmlContentInfo ci :: ContentInfo
    ci =
      ((Text, Text) -> Text -> [Node] -> Element
    qualNode' (Text
    conNS, Text
    conPrefix) "item" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map
         Element -> Node
    NodeElement
         ([[Element]] -> [Element]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat
            [ (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb ((Text, Text) -> Text -> Text -> Element
    rdfResource (Text
    conNS, Text
    conPrefix) "format") (ContentInfo -> Maybe Text
    contentFormat ContentInfo
    ci)
            , (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb ((Text, Text) -> Text -> Text -> Element
    rdfResource (Text
    conNS, Text
    conPrefix) "encoding") (ContentInfo -> Maybe Text
    contentEncoding ContentInfo
    ci)
            , (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb ([(Name, [Content])] -> Text -> Element
    rdfValue []) (ContentInfo -> Maybe Text
    contentValue ContentInfo
    ci)
            ]))
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Name -> Text -> (Name, [Content])
    mkNAttr (Text -> Name
    rdfName "about")) (ContentInfo -> Maybe Text
    contentURI ContentInfo
    ci)}

    rdfResource :: (Text, Text) -> Text -> Text -> XML.Element
    rdfResource :: (Text, Text) -> Text -> Text -> Element
    rdfResource (uri :: Text
    uri, pre :: Text
    pre) t :: Text
    t v :: Text
    v = (Text, Maybe Text) -> Text -> [(Name, [Content])] -> Element
    xmlEmpty (Text
    uri, Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    pre) Text
    t [Name -> Text -> (Name, [Content])
    mkNAttr (Text -> Name
    rdfName "resource") Text
    v]

    rdfValue :: [Attr] -> Text -> XML.Element
    rdfValue :: [(Name, [Content])] -> Text -> Element
    rdfValue as :: [(Name, [Content])]
    as s :: Text
    s = ((Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rdfNS, Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rdfPrefix) "value" Text
    s) {elementAttributes :: [(Name, [Content])]
    elementAttributes = [(Name, [Content])]
    as}

    xmlTopics :: [URIString] -> [XML.Element]
    xmlTopics :: [Text] -> [Element]
    xmlTopics [] = []
    xmlTopics xs :: [Text]
    xs =
      [ (Text, Text) -> Text -> [Node] -> Element
    qualNode'
          (Text
    taxNS, Text
    taxPrefix)
          "topics"
          [ Element -> Node
    NodeElement
              ((Text, Text) -> Text -> [Node] -> Element
    qualNode'
                 (Text
    rdfNS, Text
    rdfPrefix)
                 "Bag"
                 ((Text -> Node) -> [Text] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map (Element -> Node
    NodeElement (Element -> Node) -> (Text -> Element) -> Text -> Node
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text, Text) -> Text -> Text -> Element
    rdfResource (Text
    rdfNS, Text
    rdfPrefix) "li") [Text]
    xs))
          ]
      ]

    xmlTopic :: TaxonomyTopic -> XML.Element
    xmlTopic :: TaxonomyTopic -> Element
    xmlTopic tt :: TaxonomyTopic
    tt =
      ((Text, Text) -> Text -> [Node] -> Element
    qualNode' (Text
    taxNS, Text
    taxPrefix) "topic" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map
         Element -> Node
    NodeElement
         ((Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "link" (TaxonomyTopic -> Text
    taxonomyLink TaxonomyTopic
    tt) Element -> [Element] -> [Element]
    forall a. a -> [a] -> [a]
    :
          (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb ((Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "title") (TaxonomyTopic -> Maybe Text
    taxonomyTitle TaxonomyTopic
    tt) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb ((Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "description") (TaxonomyTopic -> Maybe Text
    taxonomyDesc TaxonomyTopic
    tt) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          [Text] -> [Element]
    xmlTopics (TaxonomyTopic -> [Text]
    taxonomyTopics TaxonomyTopic
    tt) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ (DCItem -> Element) -> [DCItem] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map DCItem -> Element
    xmlDC (TaxonomyTopic -> [DCItem]
    taxonomyDC TaxonomyTopic
    tt) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ TaxonomyTopic -> [Element]
    taxonomyOther TaxonomyTopic
    tt))
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = [Name -> Text -> (Name, [Content])
    mkNAttr (Text -> Name
    rdfName "about") (TaxonomyTopic -> Text
    taxonomyURI TaxonomyTopic
    tt)]}

    xmlItem :: Item -> XML.Element
    xmlItem :: Item -> Element
    xmlItem i :: Item
    i =
      ((Maybe Text, Maybe Text) -> Text -> [Node] -> Element
    qualNode (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "item" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map
         Element -> Node
    NodeElement
         ([ (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "title" (Item -> Text
    itemTitle Item
    i)
          , (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "link" (Item -> Text
    itemLink Item
    i)
          ] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb ((Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "description") (Item -> Maybe Text
    itemDesc Item
    i) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          (DCItem -> Element) -> [DCItem] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map DCItem -> Element
    xmlDC (Item -> [DCItem]
    itemDC Item
    i) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
          [Text] -> [Element]
    xmlTopics (Item -> [Text]
    itemTopics Item
    i) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ (ContentInfo -> Element) -> [ContentInfo] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map ContentInfo -> Element
    xmlContentInfo (Item -> [ContentInfo]
    itemContent Item
    i) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ Item -> [Element]
    itemOther Item
    i))
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = Name -> Text -> (Name, [Content])
    mkNAttr ((Text, Text) -> Text -> Name
    qualName' (Text
    rdfNS, Text
    rdfPrefix) "about") (Item -> Text
    itemURI Item
    i) (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    : Item -> [(Name, [Content])]
    itemAttrs Item
    i}

    xmlLeaf :: (Text, Maybe Text) -> Text -> Text -> XML.Element
    xmlLeaf :: (Text, Maybe Text) -> Text -> Text -> Element
    xmlLeaf (ns :: Text
    ns, pre :: Maybe Text
    pre) tg :: Text
    tg txt :: Text
    txt =
      Element :: Name -> [(Name, [Content])] -> [Node] -> Element
    Element
        { elementName :: Name
    elementName = (Maybe Text, Maybe Text) -> Text -> Name
    qualName (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    ns, Maybe Text
    pre) Text
    tg
        , elementAttributes :: [(Name, [Content])]
    elementAttributes = []
        , elementNodes :: [Node]
    elementNodes = [Content -> Node
    NodeContent (Content -> Node) -> Content -> Node
    forall a b. (a -> b) -> a -> b
    $ Text -> Content
    ContentText Text
    txt]
        }

    xmlEmpty :: (Text, Maybe Text) -> Text -> [Attr] -> XML.Element
    xmlEmpty :: (Text, Maybe Text) -> Text -> [(Name, [Content])] -> Element
    xmlEmpty (uri :: Text
    uri, pre :: Maybe Text
    pre) t :: Text
    t as :: [(Name, [Content])]
    as = ((Maybe Text, Maybe Text) -> Text -> [Node] -> Element
    qualNode (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    uri, Maybe Text
    pre) Text
    t []) {elementAttributes :: [(Name, [Content])]
    elementAttributes = [(Name, [Content])]
    as}

    ---
    mb :: (a -> b) -> Maybe a -> [b]
    mb :: (a -> b) -> Maybe a -> [b]
    mb _ Nothing = []
    mb f :: a -> b
    f (Just x :: a
    x) = [a -> b
    f a
    x]