
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_XM...
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" />

I found the error. I used "Renewable" as the name of the XML element tag
when it should have been "Renewables" with a trailing s. Oops. Sorry for
the spam -- Tim
On Tue, Jul 31, 2012 at 10:55 AM, Tim Perry
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_XM...
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" />
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
participants (1)
-
Tim Perry