如果在使用HXT在Haskell中解析RSS文件时标记丢失(If tag misses when parsing an RSS file in Haskell with HXT)
我必须在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 rssFeedsEDIT1:通过在gotoAndTake a ...的末尾添加orElse (constA“”)来解决...
I have to parse an RSS file in Haskell and I do something like:
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)My problem is that when one tag is missing, let's say "lastBuildDate" from the RSS file than I get an empty list, but I want just to replace that item with "".
How can I do that ?? Thanks,
main = do rssFeeds <- runX (parseRSS "rss.xml" >>> getRSSDetails) print rssFeedsEDIT1: Solved by adding orElse (constA "") at the end of where gotoAndTake a ...
最满意答案
通过添加解决
orElse (constA "")在......的最后
where gotoAndTake a = (getChildren >>> isElem >>> hasName a >>> getChildren >>> getText)Solved by adding
orElse (constA "")at the end of
where gotoAndTake a = (getChildren >>> isElem >>> hasName a >>> getChildren >>> getText)更多推荐
gotoAndTake,<-,>>>,RSS,电脑培训,计算机培训,IT培训"/> <meta name=
发布评论