I need to parse the RSS file in Haskell and I am doing 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, say "lastBuildDate" from the RSS file, than I get an empty list, but I just want to replace this element with "".
How can i do this? Thank,
main = do
rssFeeds <- runX (parseRSS "rss.xml" >>> getRSSDetails)
print rssFeeds
EDIT1: Solved by adding orElse(constA "") at the end, where gotoAndTake a ...
source
share