 
 (defn element->map
   "Reduces a complex HTML element into a simple Clojure map"
-  [element render-children]
+  ([element render-children]
   (let [base-element { :tag (.tagName element)
                        :text (.ownText element)}
         attributes (extract-attributes-from-element element)]

      (map #(element->map % true)
        (.children element))))
    (merge base-element {:attributes attributes}))))

(defn ? [doc xpath]
  (.select doc (name xpath)))

(defn ?? [doc xpath]
  (map #(element->map % false) (? doc xpath)))

(defn run-query [url xpath]
  (?? (get-document url) xpath))

;; ****************************************************************
;; Low level API for parsing web pages into Clojure data structures
;; ****************************************************************
(defn get-document
  "Retrieve a web page and cast it to a Document object.
   TODO: Replace the HTTP element with an async HTTP client eventually"
  [url]
  (.get (org.jsoup.Jsoup/connect url)))
