 
 (defn- parse-error [& messages]
   (throw (IllegalArgumentException. (apply str messages))))
+
+
+(defn attrs->map
+  [^Attributes attrs namespaces]
+  (let [attr-key
+        (if namespaces
+          (fn [^Attributes attrs ^Long i]
+            (let [uri (.getURI attrs i)
+                  q-name (.getQName attrs i)]
+              (if (.isEmpty uri)
+                (keyword q-name)
+                (let [[prefix _] (string/split q-name #":" 2)]
+                  (with-meta
+                    [(keyword (.getLocalName attrs i)) uri]
+                    {:prefix prefix})))))
+          (fn [^Attributes attrs ^Long i]
+            (keyword (.getQName attrs i))))]
+    (into {} (for [^Long i (range (.getLength attrs))]
+               [(attr-key attrs i) (.getValue attrs i)]))))
 
 
 (defn sax-handler

  ;; TODO - this function is way too busy
  (let [{:keys [namespaces]} opts

        attr-key
        (if namespaces
          (fn [^Attributes attrs ^Long i]
            (let [uri (.getURI attrs i)
                  q-name (.getQName attrs i)]
              (if (.isEmpty uri)
                (keyword q-name)
                (let [[prefix _] (string/split q-name #":" 2)]
                  (with-meta
                    [(keyword (.getLocalName attrs i)) uri]
                    {:prefix prefix})))))
          (fn [^Attributes attrs ^Long i]
            (keyword (.getQName attrs i))))

        attrs->map
        (fn [^Attributes attrs]
          (into {} (for [^Long i (range (.getLength attrs))]
                     [(attr-key attrs i) (.getValue attrs i)])))

        make-element
        (if namespaces
          (fn [[_ uri local-name q-name attrs] content ns-map]

                  prefix (if tag prefix nil)]
              (with-meta
                (Element. (keyword local-name)
                          attrs
                          content
                          uri)
                (if prefix
