     (catch Exception e
       (throw (Exception. (str "Error processing xpath: " original-xpath) e)))))
 
+
+(defn evaluate
+  "Returns the XPath context resulting from evaluating an XPath expression against XML or Clojure
+  data. The given context may be an XPath context, an XML string, or a Clojure data structure. The
+  given xpath-expression may be a string or a value as returned by parse-xpath."
+  [context xpath-expression]
+  (let [context (cond
+                  (xpath-context? context) context
+                  (string? context)        (create-xpath-context-for-xml context)
+                  :else                    (create-xpath-context-for-data context))
+        xpath-expression (if (string? xpath-expression)
+                           (parse-xpath xpath-expression)
+                           xpath-expression)]
+    (evaluate-internal context xpath-expression)))
+
+(defn text
+  "Returns the text of all nodes selected in an XPath context."
+  [context-or-node]
+  (cond
+    (string? context-or-node) context-or-node
+    (xpath-context? context-or-node) (apply str (map text (:context context-or-node)))
+    (:content context-or-node) (str/join (map text (:content context-or-node)))))

    (catch Exception e
      (throw (Exception. (str "Error processing xpath: " original-xpath) e)))))

(defmethod evaluate :data
  [xpath-context {:keys [source selectors original-xpath]}]
  (try
    (let [data (cond

    [(nth (as-vector data) index)]
    []))

(defn- xpath-context?
  [x]
  (and (map? x)
       (:type x)
       (:root x)
       (:context x)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Public API

