diff --git a/Text/XML/Enumerator/Parse.hs b/Text/XML/Enumerator/Parse.hs
--- a/Text/XML/Enumerator/Parse.hs
+++ b/Text/XML/Enumerator/Parse.hs
@@ -254,9 +254,7 @@
                 return $ TokenBeginDocument as
             else do
                 skipSpace
-                x <- toText <$> takeWhile (/= qmark)
-                word8' qmark
-                word8' gt
+                x <- toText . S.pack <$> manyTill anyWord8 (try $ string "?>")
                 return $ TokenInstruction $ Instruction name x
     parseComment = do
         word8' dash
@@ -626,11 +624,13 @@
                     E.drop 1
                     t <- contentToText c
                     takeContents $ front . (:) t
-                Just EventBeginDocument -> takeContents front
-                Just EventEndDocument -> takeContents front
-                Just EventInstruction{} -> takeContents front
-                Just EventDoctype{} -> takeContents front
-                Just EventComment{} -> takeContents front
+                Just EventBeginDocument -> helper
+                Just EventEndDocument -> helper
+                Just EventInstruction{} -> helper
+                Just EventDoctype{} -> helper
+                Just EventComment{} -> helper
+          where
+            helper = E.drop 1 >> takeContents front
 
 -- | The same as 'parseFile', but throws any exceptions.
 parseFile_ :: String -> (Text -> Maybe Text) -> Iteratee SEvent IO a -> IO a
diff --git a/Text/XML/Enumerator/Render.hs b/Text/XML/Enumerator/Render.hs
--- a/Text/XML/Enumerator/Render.hs
+++ b/Text/XML/Enumerator/Render.hs
@@ -103,7 +103,17 @@
 newElemStack (NSLevel _ nsmap) (Name local (Just ns) Nothing) =
     (NSLevel (Just ns) nsmap, TName Nothing local, [(TName Nothing "xmlns", [ContentText ns])])
 newElemStack (NSLevel def nsmap) (Name local (Just ns) (Just pref)) =
-    (NSLevel def nsmap', TName (Just pref) local, [(TName (Just "xmlns") pref, [ContentText ns])])
+    case Map.lookup ns nsmap of
+        Just pref'
+            | pref == pref' ->
+                ( NSLevel def nsmap
+                , TName (Just pref) local
+                , []
+                )
+        _ -> ( NSLevel def nsmap'
+             , TName (Just pref) local
+             , [(TName (Just "xmlns") pref, [ContentText ns])]
+             )
   where
     nsmap' = Map.insert ns pref nsmap
 
diff --git a/xml-enumerator.cabal b/xml-enumerator.cabal
--- a/xml-enumerator.cabal
+++ b/xml-enumerator.cabal
@@ -1,5 +1,5 @@
 name:            xml-enumerator
-version:         0.0.1
+version:         0.0.1.1
 license:         BSD3
 license-file:    LICENSE
 author:          Michael Snoyman <michaels@suite-sol.com>
