Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  XmlPickler on ADT (Tim Perry)


----------------------------------------------------------------------

Message: 1
Date: Tue, 31 Jul 2012 13:14:49 -0700
From: Tim Perry <tim.v...@gmail.com>
Subject: Re: [Haskell-beginners] XmlPickler on ADT
To: Haskell Beginners <beginners@haskell.org>
Message-ID:
        <cafvgasvbz1cnezt_fvrcjjlw75o56yjde-sfxy5dafx-h5h...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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 <tim.v...@gmail.com> wrote:

> 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/ad149d16/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 49, Issue 35
*****************************************

Reply via email to