[Haskell-beginners] HXT and missing or null values
Ian Knopke
ian.knopke at gmail.com
Thu Jun 14 18:37:06 CEST 2012
I got it. For anyone else running into the problem from my earlier
email, the way to get a null string is as follows:
Replace this line:
second <- text <<< atTag "second" -< x
with this:
second <- ((text `orElse` (constA "")) <<< atTag "second" -< x
Fixed program:
data Thing = Thing {first :: String, second :: String}
getThings = atTag "thing" >>>
proc x -> do
first <- text <<< atTag "first" -< x
second <- ((text `orElse` (constA "")) <<< atTag "second" -< x
returnA -< Thing {first = first,second = second}
atTag tag = deep (isElem >>> hasName tag)
text = getChildren >>> getText
parseThings str = runX (readString [withValidate no] str >>> getThings)
More information about the Beginners
mailing list