Contribution:
hxtPickler
Headline
XML data binding for Language:Haskell with Technology:HXT's Technology:XML pickler
Motivation
The implementation demonstrates XML data binding for Language:Haskell with Technology:HXT's Technology:XML pickler. As a result, companies can be imported from and exported to Language:XML while using algebraic data types for companies in the core functional programming. The mapping between XML and algebraic data type relies on Technology:XML pickler's type class
XMLPickler
Illustration
A Pickler for Companies
To define a pickler for companies we declare an instance of
XMLPickler
instance XmlPickler Company where
xpickle = xpCompany
The pickler function
xpCompany
xpCompany :: PU Company
xpCompany
= xpElem "company" $
xpWrap ( uncurry Company
, \c -> ( cname c
, depts c
)
) $
xpPair (xpAttr "name" xpText)
(xpList xpickle)
For implementing
xpCompany
xpElem
xpElem
xpWrap
(a -> b, b -> a) -> PU a -> PU b
b
a
b
a
PA a
In lines 4-8 the first part of the first argument of the wrapping pickler is
uncurry Company
Company
The second argument of
xpWrap
PA a
xpPair :: PU a -> PU b -> PU (a, b)
xpickle
XMLPickler
Pickling a Company
Pickling a company is realized by using arrows:
runX ( constA company
>>>
xpickleDocument xpCompany [withIndent yes] $
"sampleCompanyCut.xml"
)
A lifted sample company is passed to the arrow for pickling a document. In this case
xpickleDocument
Unpickling a Company
To unpickle a company the arrow function
xunpickleDocument
[company1] <- runX ( xunpickleDocument xpCompany $
[withRemoveWS yes] $
"sampleCompany.xml" )
runX
company1
Architecture
this!!Pickler.hs holds the pickler definitions for companies, departments and employees. The algebraic data type for companies can be found in this!!Company.hs.this!!Total.hs and this!!Cut.hs provide totaling and cutting functionality. this!!sampleCompany.xml holds a sample company. this!!Main.hs collects test scenarios for pickling/unpickling, totaling and cutting companies.
Usage
- this!!Main.hs has to be loaded into GHCi.
- The function has to be applied.
main
- The output should be equal to the content of the file this!!baseline.
There are no revisions for this page.
User contributions
User edits
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.