Question

Je dois analyser un fichier RSS dans Haskell et je fais quelque chose comme :

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)

Mon problème est que lorsqu'une balise est manquante, disons "lastBuildDate" du fichier RSS, j'obtiens une liste vide, mais je veux simplement remplacer cet élément par "".

Comment puis je faire ça ??Merci,

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

EDIT1 :Résolu en ajoutant orElse (constA "") à la fin de où gotoAndTake a ...

Était-ce utile?

La solution

Résolu en ajoutant

orElse (constA "") 

au bout du

where gotoAndTake a = (getChildren >>> 
                   isElem >>> 
                   hasName a >>> 
                   getChildren >>> 
                   getText)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top