   ;; TODO - this function is way too busy
   (let [{:keys [namespaces]} opts
 
+        ;; Memoize the metadata maps
+        md-map-with-prefix
+        (let [cache (atom nil)]
+          (fn [md-map prefix]
+            (if-let [m (get-in @cache [md-map prefix])]
+              m
+              (let [new-map (assoc md-map :prefix prefix)]
+                (swap! cache assoc-in [md-map prefix] new-map)
+                new-map))))
+        
         make-element
         (if namespaces
-          (fn [[_ uri local-name q-name attrs] content ns-map]
+          (fn [[_ uri local-name q-name attrs] content md-map]
             (let [[prefix tag] (string/split q-name #":" 2)
                   prefix (if tag prefix nil)]
               (with-meta

                      nil)))
        
        make-nodes
        (fn make-nodes [events xmlns-map]
          (loop [nodes []
                 [[type data :as evt] & events] events
                 ns-stack (list xmlns-map)]
            
            (case type
              
              :start-prefix-mapping
              (let [[_ prefix uri] evt
                    ns-map (assoc-in (peek ns-stack) [:xmlns prefix] uri)]
                (recur nodes events (conj ns-stack ns-map)))

              :end-prefix-mapping
              ;; TODO - sanity check? make sure the prefix is in the ns-map?
              (recur nodes events (pop ns-stack))
              
              :start-element
              (let [ns-map (peek ns-stack)
                    [children events] (make-nodes events ns-map)
                    elt (make-element evt children ns-map)]
                (recur (conj nodes elt)
                       events
                       ns-stack))

              :text
              (recur (conj nodes data)
                     events
                     ns-stack)

              :comment
              (recur (conj nodes (Comment. data))
                     events
                     ns-stack)

              :start-cdata
              (let [[text-nodes [end-cdata & events]]


;; New default parse options.
(def default-parse-options
  {:namespaces              true
   :keep-whitespace         false
   :comments                true
   :cdata                   true
   :processing-instructions true
   :line-numbers            false
   })

;; For backward-compatibility. Options for parsing clojure.xml-style.
(def old-parse-options
  {:namespaces              false
   :keep-whitespace         false
   :comments                false
   :cdata                   false
   :processing-instructions false
   :line-numbers            false
   })

(def ^{:dynamic true
       :doc "Map of parsing options. Any options not explitly provided
  in a call to parse will take their values from this map."}
  *parse-options* default-parse-options)

(defn parse
