[Haskell-beginners] XmlPickler on ADT

Tim Perry tim.v2.0 at gmail.com
Tue Jul 31 19:55:17 CEST 2012


Hi everyone,

I'm trying to learn to write XmlPicklers.  I've been trying to follow the
tutorial on the HaskelWiki, but it doesn't quite cover an issue I've run
into.
http://www.haskell.org/haskellwiki/HXT/Conversion_of_Haskell_data_from/to_XML

I have a ADTs like so:

data Plant = Plant
    { renewables :: [Renewable]
    , rewewableMonthly :: [RenewableMonthly]
    , waterHeating :: [WaterHeating]
    , hvac :: [HVAC]
    } deriving (Read, Show, Eq)

data Renewable = Renewable
    { dcRating :: Double -- kW
    , annualTDV :: Double -- CA Energy Comm. TDV
    } deriving (Read, Show, Eq)

data RenewableMonthly = RenewableMonthly
    { month :: Int
    , cost :: Double
    , demand :: Double
    , energy :: Double
    } deriving (Read, Show, Eq)

data WaterHeating = WaterHeating
    { whName :: String                      -- name for reference purposes.
    , whQuantity :: Int
...
data HVAC = HVAC
    { slaStatus :: String                  -- Specific leakage area
construction type.
    , newCFM50 :: Double                   -- New building leakage in
cubic feet per minute.
    , existCFM50 :: Double


I want to use an XmlPickler to read and write this.  The XML looks like
this:

<Plant>
  <Renewables DCRating="8.4" AnnualTDV="0" />
  <RenewableMonthly Month="1" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="2" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="3" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="4" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="5" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="6" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="7" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="8" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="9" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="10" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="11" Cost="0" Demand="0" Energy="0" />
  <RenewableMonthly Month="12" Cost="0" Demand="0" Energy="0" />
  <WaterHeating Name="Daikin Altherma HP" Quantity="1"
ConstructionStatus="New" EnergyFactor="2.344" SolarFraction="0" ....
  <HVAC SLAStatus="New" NewCFM50="0" ExistCFM50="0"
NewSLA="4.9000000953674316" ExistSLA="4.9" DuctStatus="New" ....
    <Zone ...


Running my code I get an error:

-- (1) readDocument: start processing document "1101_11-001 Walsh.xml" --
(1) getXmlContents: content read and decoded for
"file:///fairoaks1/all_proj/1101%20PG&E%20CAHP%2011-12/CRM/EProDataExtractPlanning/XML%20samples/1101_11-001%20Walsh.xml"
-- (1) getXmlContents' -- (1) readDocument: "1101_11-001 Walsh.xml" (mime
type: "text/xml" ) will be processed -- (1) readDocument: "1101_11-001
Walsh.xml" processed

fatal error: document unpickling failed
xpCheckEmptyContents: unprocessed XML content detected context: element
"Plant" contents:

Is it possible to write an XmlPickler for this?  Do I need to make
Renewable, RenewableMonthly, WaterHeating, and HVAC all the same type with
4 constructors and use xpAlt? Ideas?

Thanks,
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120731/0b81abff/attachment-0001.htm>


More information about the Beginners mailing list