HaXPath: An XPath-generating embedded domain specific language.

[ bsd3, library, xml ] [ Propose Tags ] [ Report a vulnerability ]

An XPath-generating embedded domain specific language, allowing construction and composition of type-safe XPaths in Haskell.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.3.0.0, 0.3.0.1
Change log CHANGELOG.md
Dependencies base (>=4.6 && <5), HList (>=0.4.0.0 && <0.6.0.0) [details]
License BSD-3-Clause
Author Huw Grano
Maintainer huw.grano@gmail.com
Category XML
Home page https://github.com/hgrano/HaXPath
Bug tracker https://github.com/hgrano/HaXPath/issues
Source repo head: git clone https://github.com/hgrano/HaXPath
Uploaded by hgrano at 2023-03-26T05:08:40Z
Distributions
Downloads 109 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for HaXPath-0.3.0.1

[back to package description]

HaXPath

HaXPath is a library and embedded domain-specifc language which uses strongly-typed Haskell expressions to represent XPaths.

Motivation

In many contexts when querying XML documents in Haskell we often need to use String values to represent the XPaths we want to use. These String expressions can quickly become hard to manage as they do not take advantage of Haskell's type system, particularly for more complex XPaths. We may not know until run-time whether the XPath is even syntactically valid. HaXPath does not have its own XPath engine to run the queries, rather it is expected to be used in combination with other libraries which have such functionality. Instead, we can simply convert the strongly-typed XPath expressions to String or Text and send them to our favourite APIs.

HaXPath API

HaXPath provides two core APIs: the standard API (HaXPath module) allows for expressing generic XPaths, while the schematic API (HaXPath.Schematic module) is a layer of abstraction built upon the standard API which constrains XPath expressions so they must follow a specifc document schema.

Standard API

HaXPath modules are expected to be imported qualified as otherwise you will get name conflicts with the Prelude. The operators however need not be qualified, and can conveniently be imported directly from HaXPath.Operators. All operators are suffixed with ., with the exception of the # operator.

Some basic examples:

https://github.com/hgrano/HaXPath/tree/master/examples/HaXPath/Examples.hs

Schematic API

The schematic API provides further constraints than the standard API by only allowing paths that are valid with respect to some custom schema. Take for example the following XML document for a restaurant menu:

<?xml version="1.0" encoding="UTF-8"?>
<menu>
  <item name="Belgian Waffles" price="$5.95"></item>
  <item name="Strawberry Waffles" price="$7.95"></item>
  <item name="French Toast" price="$4.50"></item>
</menu>

It should be fairly intuitive that there is an underlying schema to the above document. We can express this using the HaXPath.Schematic module:

https://github.com/hgrano/HaXPath/tree/master/examples/HaXPath/Schematic/Examples.hs