我必须在haskell中解析RSS文件,我做的事情如下:

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)
.

我的问题是,当缺少一个标签时,让我们从RSS文件中说出“LastBuilddate”,而不是我获得空列表,但我只想用“”替换该项目。

我该怎么做?谢谢,

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

编辑1:通过添加解决 orElse(Consta“”)在Gotoandtake的结尾处...

有帮助吗?

解决方案

通过添加来解决

orElse (constA "") 
.

结束时

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top