Package

purescript-xpath-like

Repository
bbarker/purescript-xpath-like
License
MPL-2.0
Uploaded by
bbarker
Published on
2019-07-02T20:50:02Z

Latest release Build status

Utility functions for XPaths.

Usage

Path Concatenation using //

recP :: String
recP = "record"

idP :: String
idP = "identifier"

recFromRootP :: String
recFromRootP = root // recP

idFromRootP :: String
idFromRootP = recFromRootP // idP

-- idFromRootP == "/record/identifier"

Path Concatentation with Dummy Namespace using /?

This mode of usage is particularly handy when dealing with subtleties sometimes present in XPath evaluation strategies dealing with namespaces. For examples of how this might be used in practice see examples in the tests for purescript-web-dom-xpath

recP :: String
recP = "record"

idP :: String
idP = "identifier"

recFromRootP :: String
recFromRootP = root /? recP

idFromRootP :: String
idFromRootP = recFromRootP /? idP

-- idFromRootP == "/x:record/x:identifier"

Beyond Strings

If you want more safety you can use an XPath newtype like this, instead of using String directly, but so far, I haven't seen any advantage in standardizing this (open an issue if you have thoughts):

newtype XPath = XPath String
derive instance newtypeXPath :: Newtype XPath _

We could also probably go further by typing Attributes vs Non-attribute paths, etc.

Installation

bower install purescript-xpath-like

Documentation

Module documentation is published on Pursuit.

Tests

npm run test

Modules
Data.XPath
Dependencies