Pregunta

Tengo que analizar un archivo RSS en Haskell y hago 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)

Mi problema es que cuando falta una etiqueta, digamos "LastbuildDate" del archivo RSS de lo que recibo una lista vacía, pero quiero simplemente reemplazar ese elemento con "".

¿Cómo puedo hacer eso?Gracias,

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

Editar1: Resuelto agregando orElse (Consta "") al final de dónde se goinAndetake A ...

¿Fue útil?

Solución

resuelto agregando

orElse (constA "") 

al final de

where gotoAndTake a = (getChildren >>> 
                   isElem >>> 
                   hasName a >>> 
                   getChildren >>> 
                   getText)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top