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

    import Prelude.Compat

    import Data.XML.Compat
    import Data.XML.Types as XML
    import Text.DublinCore.Types
    import Text.RSS1.Syntax
    import Text.RSS1.Utils

    import Control.Monad.Compat (guard, mplus)
    import Data.Maybe (mapMaybe)
    import Data.Text.Util

    ---
    elementToFeed :: XML.Element -> Maybe Feed
    elementToFeed :: Element -> Maybe Feed
    elementToFeed e :: Element
    e = do
      Bool -> Maybe ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Element -> Name
    elementName Element
    e Name -> Name -> Bool
    forall a. Eq a => a -> a -> Bool
    == Text -> Name
    rdfName "RDF")
      Text
    ver <- (Maybe Text, Maybe Text) -> Text -> Element -> Maybe Text
    pAttr (Maybe Text
    forall a. Maybe a
    Nothing, Maybe Text
    forall a. Maybe a
    Nothing) "xmlns" Element
    e Maybe Text -> Maybe Text -> Maybe Text
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rss10NS
      Channel
    ch <- Text -> Element -> Maybe Element
    pNode "channel" Element
    e Maybe Element -> (Element -> Maybe Channel) -> Maybe Channel
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Element -> Maybe Channel
    elementToChannel
      let mbImg :: Maybe Image
    mbImg = Text -> Element -> Maybe Element
    pNode "image" Element
    e Maybe Element -> (Element -> Maybe Image) -> Maybe Image
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Element -> Maybe Image
    elementToImage
      let is :: [Text]
    is = [Text] -> (Element -> [Text]) -> Maybe Element -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Element -> [Text]
    elementToItems (Maybe Element -> [Text]) -> Maybe Element -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Text -> Element -> Maybe Element
    pNode "items" Element
    e
      let mbTI :: Maybe TextInputInfo
    mbTI = Text -> Element -> Maybe Element
    pNode "textinput" Element
    e Maybe Element
    -> (Element -> Maybe TextInputInfo) -> Maybe TextInputInfo
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Element -> Maybe TextInputInfo
    elementToTextInput
      let ch1 :: Channel
    ch1 = Channel
    ch {channelItemURIs :: [Text]
    channelItemURIs = [Text]
    is}
      let its :: [Item]
    its = (Maybe Text, Maybe Text)
    -> Text -> (Element -> Maybe Item) -> Element -> [Item]
    forall a.
    (Maybe Text, Maybe Text)
    -> Text -> (Element -> Maybe a) -> Element -> [a]
    pMany (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "item" Element -> Maybe Item
    elementToItem Element
    e
      let es_rest :: [Element]
    es_rest = Element -> [Element]
    removeKnownElts Element
    e
      let as_rest :: [Attr]
    as_rest = Element -> [Attr]
    removeKnownAttrs Element
    e
      Feed -> Maybe Feed
    forall (m :: * -> *) a. Monad m => a -> m a
    return
        Feed :: Text
    -> Channel
    -> Maybe Image
    -> [Item]
    -> Maybe TextInputInfo
    -> [TaxonomyTopic]
    -> [Element]
    -> [Attr]
    -> Feed
    Feed
          { feedVersion :: Text
    feedVersion = Text
    ver
          , feedChannel :: Channel
    feedChannel = Channel
    ch1
          , feedImage :: Maybe Image
    feedImage = Maybe Image
    mbImg
          , feedItems :: [Item]
    feedItems = [Item]
    its
          , feedTextInput :: Maybe TextInputInfo
    feedTextInput = Maybe TextInputInfo
    mbTI
          , feedTopics :: [TaxonomyTopic]
    feedTopics =
              (Element -> Maybe TaxonomyTopic) -> [Element] -> [TaxonomyTopic]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe Element -> Maybe TaxonomyTopic
    elementToTaxonomyTopic ([Element] -> [TaxonomyTopic]) -> [Element] -> [TaxonomyTopic]
    forall a b. (a -> b) -> a -> b
    $ Name -> Element -> [Element]
    pQNodes ((Text, Text) -> Text -> Name
    qualName' (Text
    taxNS, Text
    taxPrefix) "topic") Element
    e
          , feedOther :: [Element]
    feedOther = [Element]
    es_rest
          , feedAttrs :: [Attr]
    feedAttrs = [Attr]
    as_rest
          }

    elementToItems :: XML.Element -> [URIString]
    elementToItems :: Element -> [Text]
    elementToItems = Element -> [Text]
    seqLeaves

    elementToTextInput :: XML.Element -> Maybe TextInputInfo
    elementToTextInput :: Element -> Maybe TextInputInfo
    elementToTextInput e :: Element
    e = do
      let es :: [Element]
    es = Element -> [Element]
    children Element
    e
      Text
    uri <- (Text, Text) -> Text -> Element -> Maybe Text
    pAttr' (Text
    rdfNS, Text
    rdfPrefix) "about" Element
    e
      Text
    ti <- (Text, Maybe Text) -> Text -> Element -> Maybe Text
    pQLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "title" Element
    e
      Text
    desc <- (Text, Maybe Text) -> Text -> Element -> Maybe Text
    pQLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "description" Element
    e
      Text
    na <- (Text, Maybe Text) -> Text -> Element -> Maybe Text
    pQLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "name" Element
    e
      Text
    li <- (Text, Maybe Text) -> Text -> Element -> Maybe Text
    pQLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "link" Element
    e
      let dcs :: [DCItem]
    dcs = (Element -> Maybe DCItem) -> [Element] -> [DCItem]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe Element -> Maybe DCItem
    elementToDC [Element]
    es
      TextInputInfo -> Maybe TextInputInfo
    forall (m :: * -> *) a. Monad m => a -> m a
    return
        TextInputInfo :: Text
    -> Text
    -> Text
    -> Text
    -> Text
    -> [DCItem]
    -> [Element]
    -> [Attr]
    -> TextInputInfo
    TextInputInfo
          { textInputURI :: Text
    textInputURI = Text
    uri
          , textInputTitle :: Text
    textInputTitle = Text
    ti
          , textInputDesc :: Text
    textInputDesc = Text
    desc
          , textInputName :: Text
    textInputName = Text
    na
          , textInputLink :: Text
    textInputLink = Text
    li
          , textInputDC :: [DCItem]
    textInputDC = [DCItem]
    dcs
          , textInputOther :: [Element]
    textInputOther = [Element]
    es
          , textInputAttrs :: [Attr]
    textInputAttrs = Element -> [Attr]
    elementAttributes Element
    e
          }

    elementToItem :: XML.Element -> Maybe Item
    elementToItem :: Element -> Maybe Item
    elementToItem e :: Element
    e = do
      Bool -> Maybe ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Element -> Name
    elementName Element
    e Name -> Name -> Bool
    forall a. Eq a => a -> a -> Bool
    == (Maybe Text, Maybe Text) -> Text -> Name
    qualName (Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "item")
      let es :: [Element]
    es = Element -> [Element]
    children Element
    e
      Text
    uri <- (Text, Text) -> Text -> Element -> Maybe Text
    pAttr' (Text
    rdfNS, Text
    rdfPrefix) "about" Element
    e
      Text
    ti <- (Text, Maybe Text) -> Text -> Element -> Maybe Text
    pQLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "title" Element
    e
      Text
    li <- (Text, Maybe Text) -> Text -> Element -> Maybe Text
    pQLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "link" Element
    e
      let desc :: Maybe Text
    desc = (Text, Maybe Text) -> Text -> Element -> Maybe Text
    pQLeaf (Text
    rss10NS, Maybe Text
    forall a. Maybe a
    Nothing) "description" Element
    e
      let dcs :: [DCItem]
    dcs = (Element -> Maybe DCItem) -> [Element] -> [DCItem]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe Element -> Maybe DCItem
    elementToDC [Element]
    es
      let tos :: [Text]
    tos = [Text] -> (Element -> [Text]) -> Maybe Element -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Element -> [Text]
    bagLeaves (Maybe Element -> [Text]) -> Maybe Element -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Name -> Element -> Maybe Element
    pQNode ((Text, Text) -> Text -> Name
    qualName' (Text
    taxNS, Text
    taxPrefix) "topics") Element
    e
      let cs :: [ContentInfo]
    cs = (Element -> Maybe ContentInfo) -> [Element] -> [ContentInfo]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe Element -> Maybe ContentInfo
    elementToContent [Element]
    es
      let es_other :: [Element]
    es_other = Element -> [Element]
    removeKnownElts Element
    e
      let as_other :: [Attr]
    as_other = Element -> [Attr]
    removeKnownAttrs Element
    e
      Item -> Maybe Item
    forall (m :: * -> *) a. Monad m => a -> m a
    return
        Item :: Text
    -> Text
    -> Text
    -> Maybe Text
    -> [DCItem]
    -> [Text]
    -> [ContentInfo]
    -> [Element]
    -> [Attr]
    -> Item
    Item
          { itemURI :: Text
    itemURI = Text
    uri
          , itemTitle :: Text
    itemTitle = Text
    ti
          , itemLink :: Text
    itemLink = Text
    li
          , itemDesc :: Maybe Text
    itemDesc = Maybe Text
    desc
          , itemDC :: [DCItem]
    itemDC = [DCItem]
    dcs
          , itemTopics :: [Text]
    itemTopics = [Text]
    tos
          , itemContent :: [ContentInfo]
    itemContent = [ContentInfo]
    cs
          , itemOther :: [Element]
    itemOther = [Element]
    es_other
          , itemAttrs :: [Attr]
    itemAttrs = [Attr]
    as_other
          }

    elementToImage :: XML.Element -> Maybe Image
    elementToImage :: Element -> Maybe Image
    elementToImage e :: Element
    e = do
      let es :: [Element]
    es = Element -> [Element]
    children Element
    e
      let as :: [Attr]
    as = Element -> [Attr]
    elementAttributes Element
    e
      Text
    uri <- (Text, Text) -> Text -> Element -> Maybe Text
    pAttr' (Text
    rdfNS, Text
    rdfPrefix) "about" Element
    e
      Text
    ti <- Text -> Element -> Maybe Text
    pLeaf "title" Element
    e
      Text
    ur <- Text -> Element -> Maybe Text
    pLeaf "url" Element
    e
      Text
    li <- Text -> Element -> Maybe Text
    pLeaf "link" Element
    e
      let dcs :: [DCItem]
    dcs = (Element -> Maybe DCItem) -> [Element] -> [DCItem]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe Element -> Maybe DCItem
    elementToDC [Element]
    es
      Image -> Maybe Image
    forall (m :: * -> *) a. Monad m => a -> m a
    return
        Image :: Text
    -> Text -> Text -> Text -> [DCItem] -> [Element] -> [Attr] -> Image
    Image
          { imageURI :: Text
    imageURI = Text
    uri
          , imageTitle :: Text
    imageTitle = Text
    ti
          , imageURL :: Text
    imageURL = Text
    ur
          , imageLink :: Text
    imageLink = Text
    li
          , imageDC :: [DCItem]
    imageDC = [DCItem]
    dcs
          , imageOther :: [Element]
    imageOther = [Element]
    es
          , imageAttrs :: [Attr]
    imageAttrs = [Attr]
    as
          }

    elementToChannel :: XML.Element -> Maybe Channel
    elementToChannel :: Element -> Maybe Channel
    elementToChannel e :: Element
    e = do
      let es :: [Element]
    es = Element -> [Element]
    children Element
    e
      Text
    uri <- (Text, Text) -> Text -> Element -> Maybe Text
    pAttr' (Text
    rdfNS, Text
    rdfPrefix) "about" Element
    e
      Text
    ti <- Text -> Element -> Maybe Text
    pLeaf "title" Element
    e
      Text
    li <- Text -> Element -> Maybe Text
    pLeaf "link" Element
    e
      Text
    de <- Text -> Element -> Maybe Text
    pLeaf "description" Element
    e
      let mbImg :: Maybe Text
    mbImg = Text -> Element -> Maybe Text
    pLeaf "image" Element
    e
      let is :: [Text]
    is = [Text] -> (Element -> [Text]) -> Maybe Element -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Element -> [Text]
    seqLeaves (Maybe Element -> [Text]) -> Maybe Element -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Text -> Element -> Maybe Element
    pNode "items" Element
    e
      let tinp :: Maybe Text
    tinp = Text -> Element -> Maybe Text
    pLeaf "textinput" Element
    e
      let dcs :: [DCItem]
    dcs = (Element -> Maybe DCItem) -> [Element] -> [DCItem]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe Element -> Maybe DCItem
    elementToDC [Element]
    es
      let tos :: [Text]
    tos = [Text] -> (Element -> [Text]) -> Maybe Element -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Element -> [Text]
    bagLeaves (Maybe Element -> [Text]) -> Maybe Element -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Name -> Element -> Maybe Element
    pQNode ((Text, Text) -> Text -> Name
    qualName' (Text
    taxNS, Text
    taxPrefix) "topics") Element
    e
      let cs :: [ContentInfo]
    cs = (Element -> Maybe ContentInfo) -> [Element] -> [ContentInfo]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe Element -> Maybe ContentInfo
    elementToContent [Element]
    es
      let es_other :: [Element]
    es_other = Element -> [Element]
    removeKnownElts Element
    e
      let as_other :: [Attr]
    as_other = Element -> [Attr]
    removeKnownAttrs Element
    e
      let def_chan :: Channel
    def_chan =
            Channel :: Text
    -> Text
    -> Text
    -> Text
    -> Maybe Text
    -> [Text]
    -> Maybe Text
    -> [DCItem]
    -> Maybe UpdatePeriod
    -> Maybe Integer
    -> Maybe Text
    -> [ContentInfo]
    -> [Text]
    -> [Element]
    -> [Attr]
    -> Channel
    Channel
              { channelURI :: Text
    channelURI = Text
    uri
              , channelTitle :: Text
    channelTitle = Text
    ti
              , channelLink :: Text
    channelLink = Text
    li
              , channelDesc :: Text
    channelDesc = Text
    de
              , channelImageURI :: Maybe Text
    channelImageURI = Maybe Text
    mbImg
              , channelItemURIs :: [Text]
    channelItemURIs = [Text]
    is
              , channelTextInputURI :: Maybe Text
    channelTextInputURI = Maybe Text
    tinp
              , channelDC :: [DCItem]
    channelDC = [DCItem]
    dcs
              , channelUpdatePeriod :: Maybe UpdatePeriod
    channelUpdatePeriod = Maybe UpdatePeriod
    forall a. Maybe a
    Nothing
              , channelUpdateFreq :: Maybe Integer
    channelUpdateFreq = Maybe Integer
    forall a. Maybe a
    Nothing
              , channelUpdateBase :: Maybe Text
    channelUpdateBase = Maybe Text
    forall a. Maybe a
    Nothing
              , channelContent :: [ContentInfo]
    channelContent = [ContentInfo]
    cs
              , channelTopics :: [Text]
    channelTopics = [Text]
    tos
              , channelOther :: [Element]
    channelOther = [Element]
    es_other
              , channelAttrs :: [Attr]
    channelAttrs = [Attr]
    as_other
              }
      Channel -> Maybe Channel
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Element -> Channel -> Channel
    addSyndication Element
    e Channel
    def_chan)

    addSyndication :: XML.Element -> Channel -> Channel
    addSyndication :: Element -> Channel -> Channel
    addSyndication e :: Element
    e ch :: Channel
    ch =
      Channel
    ch
        { channelUpdatePeriod :: Maybe UpdatePeriod
    channelUpdatePeriod = Text -> UpdatePeriod
    forall a. (Eq a, IsString a) => a -> UpdatePeriod
    toUpdatePeriod (Text -> UpdatePeriod) -> Maybe Text -> Maybe UpdatePeriod
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Text, Text) -> Text -> Element -> Maybe Text
    pQLeaf' (Text
    synNS, Text
    synPrefix) "updatePeriod" Element
    e
        , channelUpdateFreq :: Maybe Integer
    channelUpdateFreq = Text -> Maybe Integer
    readInt (Text -> Maybe Integer) -> Maybe Text -> Maybe Integer
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< (Text, Text) -> Text -> Element -> Maybe Text
    pQLeaf' (Text
    synNS, Text
    synPrefix) "updateFrequency" Element
    e
        , channelUpdateBase :: Maybe Text
    channelUpdateBase = (Text, Text) -> Text -> Element -> Maybe Text
    pQLeaf' (Text
    synNS, Text
    synPrefix) "updateBase" Element
    e
        }
      where
        toUpdatePeriod :: a -> UpdatePeriod
    toUpdatePeriod x :: a
    x =
          case a
    x of
            "hourly" -> UpdatePeriod
    Update_Hourly
            "daily" -> UpdatePeriod
    Update_Daily
            "weekly" -> UpdatePeriod
    Update_Weekly
            "monthly" -> UpdatePeriod
    Update_Monthly
            "yearly" -> UpdatePeriod
    Update_Yearly
            _ -> UpdatePeriod
    Update_Hourly -- ToDo: whine

    elementToDC :: XML.Element -> Maybe DCItem
    elementToDC :: Element -> Maybe DCItem
    elementToDC e :: Element
    e = do
      Bool -> Maybe ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Name -> Maybe Text
    nameNamespace (Element -> Name
    elementName Element
    e) Maybe Text -> Maybe Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    dcNS)
      let dcItem :: DCInfo -> DCItem
    dcItem x :: DCInfo
    x = DCItem :: DCInfo -> Text -> DCItem
    DCItem {dcElt :: DCInfo
    dcElt = DCInfo
    x, dcText :: Text
    dcText = Element -> Text
    strContent Element
    e}
      DCItem -> Maybe DCItem
    forall (m :: * -> *) a. Monad m => a -> m a
    return (DCItem -> Maybe DCItem) -> DCItem -> Maybe DCItem
    forall a b. (a -> b) -> a -> b
    $
        DCInfo -> DCItem
    dcItem (DCInfo -> DCItem) -> DCInfo -> DCItem
    forall a b. (a -> b) -> a -> b
    $
        case Name -> Text
    nameLocalName (Name -> Text) -> Name -> Text
    forall a b. (a -> b) -> a -> b
    $ Element -> Name
    elementName Element
    e of
          "title" -> DCInfo
    DC_Title
          "creator" -> DCInfo
    DC_Creator
          "subject" -> DCInfo
    DC_Subject
          "description" -> DCInfo
    DC_Description
          "publisher" -> DCInfo
    DC_Publisher
          "contributor" -> DCInfo
    DC_Contributor
          "date" -> DCInfo
    DC_Date
          "type" -> DCInfo
    DC_Type
          "format" -> DCInfo
    DC_Format
          "identifier" -> DCInfo
    DC_Identifier
          "source" -> DCInfo
    DC_Source
          "language" -> DCInfo
    DC_Language
          "relation" -> DCInfo
    DC_Relation
          "coverage" -> DCInfo
    DC_Coverage
          "rights" -> DCInfo
    DC_Rights
          oth :: Text
    oth -> Text -> DCInfo
    DC_Other Text
    oth

    elementToTaxonomyTopic :: XML.Element -> Maybe TaxonomyTopic
    elementToTaxonomyTopic :: Element -> Maybe TaxonomyTopic
    elementToTaxonomyTopic e :: Element
    e = do
      Bool -> Maybe ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Element -> Name
    elementName Element
    e Name -> Name -> Bool
    forall a. Eq a => a -> a -> Bool
    == (Text, Text) -> Text -> Name
    qualName' (Text
    taxNS, Text
    taxPrefix) "topic")
      let es :: [Element]
    es = Element -> [Element]
    children Element
    e
      Text
    uri <- (Text, Text) -> Text -> Element -> Maybe Text
    pAttr' (Text
    rdfNS, Text
    rdfPrefix) "about" Element
    e
      Text
    li <- (Text, Text) -> Text -> Element -> Maybe Text
    pQLeaf' (Text
    taxNS, Text
    taxPrefix) "link" Element
    e
      TaxonomyTopic -> Maybe TaxonomyTopic
    forall (m :: * -> *) a. Monad m => a -> m a
    return
        TaxonomyTopic :: Text
    -> Text
    -> Maybe Text
    -> Maybe Text
    -> [Text]
    -> [DCItem]
    -> [Element]
    -> TaxonomyTopic
    TaxonomyTopic
          { taxonomyURI :: Text
    taxonomyURI = Text
    uri
          , taxonomyLink :: Text
    taxonomyLink = Text
    li
          , taxonomyTitle :: Maybe Text
    taxonomyTitle = Text -> Element -> Maybe Text
    pLeaf "title" Element
    e
          , taxonomyDesc :: Maybe Text
    taxonomyDesc = Text -> Element -> Maybe Text
    pLeaf "description" Element
    e
          , taxonomyTopics :: [Text]
    taxonomyTopics = [Text] -> (Element -> [Text]) -> Maybe Element -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Element -> [Text]
    bagLeaves (Maybe Element -> [Text]) -> Maybe Element -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Name -> Element -> Maybe Element
    pQNode ((Text, Text) -> Text -> Name
    qualName' (Text
    taxNS, Text
    taxPrefix) "topics") Element
    e
          , taxonomyDC :: [DCItem]
    taxonomyDC = (Element -> Maybe DCItem) -> [Element] -> [DCItem]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe Element -> Maybe DCItem
    elementToDC [Element]
    es
          , taxonomyOther :: [Element]
    taxonomyOther = [Element]
    es
          }

    elementToContent :: XML.Element -> Maybe ContentInfo
    elementToContent :: Element -> Maybe ContentInfo
    elementToContent e :: Element
    e = do
      Bool -> Maybe ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Element -> Name
    elementName Element
    e Name -> Name -> Bool
    forall a. Eq a => a -> a -> Bool
    == (Text, Text) -> Text -> Name
    qualName' (Text
    conNS, Text
    conPrefix) "items")
      ContentInfo -> Maybe ContentInfo
    forall (m :: * -> *) a. Monad m => a -> m a
    return
        ContentInfo :: Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> ContentInfo
    ContentInfo
          { contentURI :: Maybe Text
    contentURI = (Text, Text) -> Text -> Element -> Maybe Text
    pAttr' (Text
    rdfNS, Text
    rdfPrefix) "about" Element
    e
          , contentFormat :: Maybe Text
    contentFormat = (Text, Text) -> Text -> Element -> Maybe Text
    pQLeaf' (Text
    conNS, Text
    conPrefix) "format" Element
    e
          , contentEncoding :: Maybe Text
    contentEncoding = (Text, Text) -> Text -> Element -> Maybe Text
    pQLeaf' (Text
    conNS, Text
    conPrefix) "encoding" Element
    e
          , contentValue :: Maybe Text
    contentValue = (Text, Text) -> Text -> Element -> Maybe Text
    pQLeaf' (Text
    rdfNS, Text
    rdfPrefix) "value" Element
    e
          }

    bagLeaves :: XML.Element -> [URIString]
    bagLeaves :: Element -> [Text]
    bagLeaves be :: Element
    be =
      (Element -> Maybe Text) -> [Element] -> [Text]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe
        (\e :: Element
    e -> do
           Bool -> Maybe ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Element -> Name
    elementName Element
    e Name -> Name -> Bool
    forall a. Eq a => a -> a -> Bool
    == (Text, Text) -> Text -> Name
    qualName' (Text
    rdfNS, Text
    rdfPrefix) "li")
           (Text, Text) -> Text -> Element -> Maybe Text
    pAttr' (Text
    rdfNS, Text
    rdfPrefix) "resource" Element
    e Maybe Text -> Maybe Text -> Maybe Text
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus`
             (Element -> Text) -> Maybe Element -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Element -> Text
    strContent (Name -> Element -> Maybe Element
    pQNode ((Text, Text) -> Text -> Name
    qualName' (Text
    rdfNS, Text
    rdfPrefix) "li") Element
    e))
        ([Element] -> (Element -> [Element]) -> Maybe Element -> [Element]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Element -> [Element]
    children (Maybe Element -> [Element]) -> Maybe Element -> [Element]
    forall a b. (a -> b) -> a -> b
    $ Name -> Element -> Maybe Element
    pQNode ((Text, Text) -> Text -> Name
    qualName' (Text
    rdfNS, Text
    rdfPrefix) "Bag") Element
    be)

    {-
    bagElements :: XML.Element -> [XML.Element]
    bagElements be =
      mapMaybe
        (\ e -> do
          guard (elementName e == rdfName "li")
          return e)
        (fromMaybe [] $ fmap children $ pQNode (rdfName "Bag") be)
    -}
    seqLeaves :: XML.Element -> [URIString]
    seqLeaves :: Element -> [Text]
    seqLeaves se :: Element
    se =
      (Element -> Maybe Text) -> [Element] -> [Text]
    forall a b. (a -> Maybe b) -> [a] -> [b]
    mapMaybe
        (\e :: Element
    e -> do
           Bool -> Maybe ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Element -> Name
    elementName Element
    e Name -> Name -> Bool
    forall a. Eq a => a -> a -> Bool
    == Text -> Name
    rdfName "li")
           Text -> Maybe Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Element -> Text
    strContent Element
    e))
        ([Element] -> (Element -> [Element]) -> Maybe Element -> [Element]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Element -> [Element]
    children (Maybe Element -> [Element]) -> Maybe Element -> [Element]
    forall a b. (a -> b) -> a -> b
    $ Name -> Element -> Maybe Element
    pQNode (Text -> Name
    rdfName "Seq") Element
    se)