Closed orlitzky closed 10 years ago
here is a change in the pickler for league, that works with validation and without. xpText0 accepts empty string (xpText does not) and the empty string is mapped to a maybe value.
pickle_league :: PU WeatherLeague
pickle_league =
xpElem "league" $
xpWrap (from_pair, to_pair) $
xpPair
(xpAttr "name" $
xpWrap (\ x -> if null x then Nothing else Just x
, fromMaybe ""
) xpText0
)
(xpList pickle_listing)
where
from_pair = uncurry WeatherLeague
to_pair WeatherLeague{..} = (league_name, listings)
The whole code becomes simpler if League is defined without Maybe
data WeatherLeague =
WeatherLeague {
league_name :: String,
listings :: [WeatherListing] }
deriving (Eq, Show)
In that case the pickler becomes
xpAttr "name" xpText0
At the moment I don't have any idea, why the pickler behaved different for validated and not validated documents. I could reproduce the error, but I have not seen any differences in the XML trees. I will have a look into that. I hope you can live with that workaround.
Cheer, Uwe
Yeah I've worked around it for now. I almost ate my monitor when I figured out that "withValidate no" was making it fail to unpickle though =P
I found this rather strange:
https://gist.github.com/mjorlitzky/8431680
There is a bug in my unpickling code; the line,
should instead be,
since it is the attribute text and not the attribute itself that is optional. But even so, the former translates into,
which in my current state of unsleep does nothing to explain the following: