Skip to content

hubbards/xpath-kotlin

Repository files navigation

xpath-kotlin

Test

This project contains a shallow embedded domain-specific language (DSL) of XPath in Kotlin. More pragmatically, this DSL is a type-safe builder for XPath expressions.

Introduction

Consider the following XPath expression, which tests if there are fewer than 3 ordered list items in a document.

3 > count(//ol/li)

Such an expression can be evaluated in Java using the javax.xml.xpath package but the expression must be encoded as a String. Using this XPath DSL, we can build a value equivalent to the XPath expression above in a structured way.

run {
  val three = LiteralNumber(3)
  val items = absolute {
    descendantOrSelf()
    child("ol")
    child("li")
  }
  three greaterThan count(items)
}

Development Instructions

This section is intended for developers of the project. Clients of the project may safely skip this section.

We will assume that this project exists locally and we are logged into a shell where the working directory is the root of the project. We will also assume that Java version 8 or higher is installed.

Build

Build the project with the command ./gradlew build.

Test

Run the unit tests for the project with the command ./gradlew test.