如果在使用HXT在Haskell中解析RSS文件时标记丢失(If tag misses when parsing an RSS file in Haskell with HXT)

编程入门 行业动态 更新时间:2024-10-25 06:20:56
如果在使用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 rssFeeds

EDIT1:通过在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 rssFeeds

EDIT1: 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=

本文发布于:2023-08-06 19:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标记   文件   Haskell   RSS   HXT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!