Jump to content

HaXml

From Wikipedia, the free encyclopedia

{{#invoke:Infobox|infobox}}Template:Template other {{#invoke:Check for unknown parameters|check|unknown=Template:Main other|preview=Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y| AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo class | logo size | logo title | logo upright | logo_alt | logo_caption | logo_class | logo_size | logo_title | logo_upright | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | qid | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot class | screenshot size | screenshot title | screenshot upright | screenshot_alt | screenshot_class | screenshot_size | screenshot_upright | service_name | size | standard | title | ver layout | website }}Template:Main other{{#invoke:Check for conflicting parameters|check | template = Template:Infobox software | cat = Template:Main other | logo size; logo_size | logo class; logo_class | logo alt; logo_alt | logo title; logo_title | logo caption; logo_caption | screenshot size; screenshot_size | screenshot upright; screenshot_upright | screenshot class; screenshot_class | screenshot alt; screenshot_alt | screenshot title; screenshot title | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | programming language; programming_language | operating system; operating_system }}

HaXml is a collection of utilities for parsing, filtering, transforming, and generating Extensible Markup Language (XML) documents using the programming language Haskell.[1]

Overview

HaXml utilities include:[1][2]

HaXml provides a combinator library with a set of higher-order functions which process the XML documents after they are represented using the native Haskell data types.[3] The basic data type is Content which represents the document subset of XML.[4]

HaXml allows converting XML to Haskell data and vice versa, and XML to XML (by transforming or filtering). The common use of the HaXml's parser includes defining the method of traversing the XML data and it has the CFilter type (content filter), where type CFilter = Content -> [Content]. It means that this function defined by the user will take a fragment of an XML data and either return more fragments or none at all. This approach allows to choose XML elements satisfying certain conditions (e.g., tags with certain name or all children of a specified tag).[5][6]

Example

In the chapter 22 "Extended Example: Web Client Programming" of the Real World Haskell by Bryan O'Sullivan, Don Stewart, and John Goerzen, the following example is considered.[5] The XML file looks like this (simplified version):

<syntaxhighlight lang="xml"> <?xml version="1.0" encoding="UTF-8"?> <rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" version="2.0">

 <channel>
   <title>Haskell Radio</title>
   <link>http://www.example.com/radio/</link>
   <description>Description of this podcast</description>
   <item>First item</item>
   <item>Second item</item>
 </channel>

</rss> </syntaxhighlight>

The following content filter is constructed:

<syntaxhighlight lang="haskell"> channel :: CFilter channel = tag "rss" /> tag "channel" </syntaxhighlight>

This filter is later used to get the title of the channel:

<syntaxhighlight lang="haskell"> getTitle :: Content -> String getTitle doc = contentToStringDefault "Untitled Podcast" (channel /> tag "title" /> txt $ doc) </syntaxhighlight>

References

Template:Reflist

Template:Haskell programming