MyNixOS website logo
Description

An XPath-generating embedded domain specific language.

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

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.

Metadata

Version

0.3.0.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows