Pergunta

Tenho que analisar um arquivo RSS em Haskell e faço algo como:

atTag tag = deep (isElem >>> hasName tag)
getRSSDetails = atTag "channel" >>>
   proc p -> do 
      fTitle         <- gotoAndTake "title"        -< p
      fLink          <- gotoAndTake "link"         -< p
      fDescription   <- gotoAndTake "description"  -< p
      fLanguage      <- gotoAndTake "language"     -< p
      fGenerator     <- gotoAndTake "generator"    -< p
      fCopyright     <- gotoAndTake "copyright"    -< p
      fWebMaster     <- gotoAndTake "webMaster"    -< p
      fLastBuildDate <- gotoAndTake "lastBuildDate" -< p
                where gotoAndTake a = (getChildren >>> 
                          isElem >>> 
                          hasName a >>> 
                          getChildren >>> 
                          getText)

Meu problema é que quando uma tag está faltando, digamos "lastBuildDate" do arquivo RSS, recebo uma lista vazia, mas quero apenas substituir esse item por "".

Como eu posso fazer isso ??Obrigado,

main = do
   rssFeeds <- runX (parseRSS "rss.xml" >>> getRSSDetails)
   print rssFeeds

EDITAR1:Resolvido adicionando orElse (constA "") no final de onde gotoAndTake a ...

Foi útil?

Solução

Resolvido adicionando

orElse (constA "") 

no fim de

where gotoAndTake a = (getChildren >>> 
                   isElem >>> 
                   hasName a >>> 
                   getChildren >>> 
                   getText)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top