    ;; FIXME XDM keys have only been mocked; unknown if it matches getValueType
 
    ;; XdmAtomic TODO
-   ;; XdmAttribute TODO
+   "attribute()" #(.asString %) ;; XdmAttribute TODO
    "binary()" #(.asString %) ;; XdmBinary -- XXX unknown if the key used matches getValueType
-   "comment()" #(.asString %) ;; XdmComment -- XXX unknown if the key used matches getValueType
-   "document()" #(.asString % ) ;; XdmDocument
-   "duration()" #(.toString %) ;; XdmDuration
+   "comment()" #(.asString %) ;; XdmComment
+   "document-node()" #(.asString %) ;; XdmDocument
+   "duration()" #(.toString %) ;; XdmDuration XXX may only ever come through as xs:duration
    "element()" #(.asString %) ;; XdmElement
    ;; XdmItem TODO
-   ;; XdmNode TODO
-   ;; XdmProcessingInstruction TODO
-   ;; XdmSequence<I extends XdmItem> TODO
-   "text()" #(.asString %)   ;; XdmText -- XXX unknown if the key used matches getValueType
+   "text()" #(.asString %)
+   ;; XdmText -- XXX unknown if the key used matches getValueType
    "variable()" #(hash-map (.toString (.getName %))
                            (.asString (.getValue %))) ;; XdmVariable -- XXX unknown if the key used matches getValueType
 

   "xs:gYear" str
   "xs:gYearMonth" str
   "xs:hexBinary" str ;; looks OK but test with real doc
   "xs:integer" coerce-number
   "xs:string" str
   "xs:time" str
   "xs:untypedAtomic" str ;; NB: also referred to as "xdt:untypedAtomic" in type listing
   "xs:yearMonthDuration" str})

(defn result-type
  ;; TODO docstring
  ;; XXX assumes result is homogenous
  [result]
  (.toString (.getValueType (first (.toArray result)))))

;; TODO allow user to pass in their own map of types (to be `merge`d)
(defn coerce
  ;; XXX is this named optimally?
  ;; TODO docstring
  [result-sequence]
  ;; TODO throw informative exception if type not found in types
  (let [result (map (fn [item] ((types (.toString (.getValueType item))) item))
                    (.toArray result-sequence))]
    (if (= 1 (count result))
      (first result)
      result)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Helpers for sessions and requests

;;;; Type coercion
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn convert-number
  "Reads a number from a numeric Java object of a type from
  com.marklogic.xcc.types. Returns nil if not a number. Designed for
  robust number-handling while preventing read-string security
