The XPath specs define a number of useful functions which are specific to XML, other string or number related functionality is provided by Scala itself and is not replicated by the XPath DSL.
The XPath Functions are organised into two main type classes:
Names provides a type class for any type that can represent a QName:
TextValue, representing everything that can produce a text value, has a similar base list:
In general if any logical combination thereof is possible they are also supported (for example XmlPaths themselves)
The boolean family of type class instances:
and of course
The full list of functions is available here.
Some examples:
val attr : Attribute = "attr" -> "value" qname(attr) // attr pqName(attr) // {}attr namespaceUri(attr) // "" val ns = Namespace("uri:namespace") val pre = ns.prefixed("pre") val prefixedAttr : Attribute = pre("prefixed") -> "prefixed value" qname(prefixedAttr) // pre:prefixed pqName(prefixedAttr) // pre:{uri:namespace}prefixed namespaceUri(prefixedAttr) // uri:namespace val elem = Elem(pre("prefixedElem")) qname(elem) // pre:prefixedElem pqName(elem) // pre:{uri:namespace}prefixedElem namespaceUri(elem) // uri:namespace val tree = elem /( elem ~> "\ndeep value\n" ) pqName(tree) // pre:{uri:namespace}prefixedElem
Using the `name` function with a non QName XPath (e.g. an XmlItem) will result in an exception.
The full list of functions is available here.
Some examples (using the above definitions):
value(attr) // value value(prefixedAttr) // prefixed value // won't compile as there is no meaningful way to get an elems value // value(elem) value(tree.toTree) // \ndeep value\n normalizeSpace(tree) // deep value, but using type class directly
boolean("") // false boolean("value") // true boolean(true) // true