 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Emitting XML
 
+(def ^:dynamic *emitter-state* nil)
+
+(defn update-emitter-state [elt]
+  )
+
+(defn valid-prefix?
+  "Returns true if the given prefix is valid for the uri, for the current value
+   of *emitter-state*."
+  [prefix uri]
+  (let [declared-prefixes (get-in *emitter-state* [:prefixes uri])]
+    (some #(= prefix %) declared-prefixes)))
+
+
+(defprotocol XMLPrefix
+  (prefix-for [this] "Returns the prefix to use for "))
+
+(extend-protocol XMLPrefix
+  
+  Element
+  (prefix-for [elt]
+    (if-let [uri (uri elt)]
+      (or (:prefix (meta elt))
+          (peek (get-in *emitter-state* [:prefixes uri])))))
+
+  ;; Namespaced attribute
+  clojure.lang.IPersistentVector
+  (prefix-for [[name uri :as attr]]
+    ())
+
+  ;; Non-namespaced attribute
+  clojure.lang.Keyword
+  (prefix-for [_]
+    nil)
+  )
+
+
 (defprotocol XMLWritable
   (emit-xml [this ^Writer out]))
 



(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 true, the parser will put line-numbers and column-numbers
       in the metadata of elements, when supported by the SAX parser.

     :xmlns-aware
       Sets namespace-awareness in the SAX parser. See below.

   Namespace-awareness has the following effects:
