Headline

In-memory XML processing in Language:Haskell with Technology:HXT

Motivation

The implementation demonstrates XML processing in Language:Haskell with Technology:HXT's combinator library. Operations for totaling and cutting salaries are accordingly composed from combinators for XML queries and transformations. The concept of arrows is demonstrated by the implementation as HXT's combinator library essentially relies on arrows.

Illustration

In the following we will demonstrate the construction of an arrow for Feature:Total and how one can run this arrow in IO.

Total

We define a query for totaling all company salaries:

total :: ArrowXml a => a XmlTree Float
total = listA (deep $ hasName "salary"
               >>> 
               getChildren  
               >>> 
               getText)     
        >>>
        arr (sum.(map read)) 

In line 2 we query all salary nodes by using

deep $ hasName "salary" :: ArrowXml a => a XmlTree XmlTree
. This is an arrow from
XmlTree
to
XmlTree
, say a filter for all salary nodes. In general
deep
only finds non-nested results, but because of the fact that we are dealing with text nodes, which can not be nested, this is acceptable in this situation. In lines 2-6 the result of this arrow is then combined with
getChildren >>> getText
by using
>>>
. The new arrow of type
ArrowXml a => a XmlTree String
returns the text of each salary node.

We then use Control.Arrow.ArrowLists

listA
in line 2 to collect all results from this arrow in an array, giving us a new arrow of type
ArrowXml a => a XmlTree [String]
.

In line 7 the result of this arrow is passed to the lifted version of

(sum.(map read)) :: (Read c, Num c) => [String] -> c
, which in this case is of type:
ArrowXml a => a [String] Float
.

The overall emerging arrow, giving us the total salary, is of type

ArrowXml a => a XmlTree Float
.

Running an arrow

When we combinate the arrow for reading a sample company from a XML file with the totaling arrow we get:

readDocument [] "sampleCompany.xml" >>> total

We use

runX :: IOSArrow XmlTree c -> IO [c]
for running this arrow in IO. The function returns all results of a given arrow in a list. Because we except this list to be a singleton list, we can write:

[ttl] <- runX ( readDocument [] "sampleCompany.xml" 
                >>> total )
ttl
holds the total salary of a sample company.

Architecture

this!!Total.hs provides the arrow for totaling salaries as described in the illustration section. this!!Cut.hs contains a transformation arrow for cutting salaries. this!!Main.hs collects test scenarios for totaling and cutting XML data provided by this!!sampleCompany.xml

Usage

function has to be applied. One can also use the this!!Makefile with a target test for test automation.

Metadata


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    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.