-
Notifications
You must be signed in to change notification settings - Fork 3
/
saxon.clj
35 lines (24 loc) · 1.03 KB
/
saxon.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(ns sigel.saxon
(:import (net.sf.saxon Configuration)
(net.sf.saxon.s9api DocumentBuilder Processor)))
(def ^Configuration configuration
"A default Saxon [Configuration](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/Configuration.html)."
(Configuration.))
(def ^Processor processor
"A default Saxon [Processor](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Processor.html)."
(Processor. configuration))
(def ^DocumentBuilder builder
"A Saxon [DocumentBuilder](http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/DocumentBuilder.html)."
(.newDocumentBuilder processor))
(defn xdmvalue->object
"Get the value of an XdmValue as the nearest equivalent Java object.
If the XdmValue is a node, return the string value of that node.
Example:
```
(class (xdmvalue->object (xpath/select \"<num>1</num>\" \"xs:integer(num)\")))
;;=> java.math.BigInteger
```"
[value]
(if (.isAtomicValue value)
(.getValue value)
(.getStringValue value)))