Index: src/java/org/apache/fop/image/analyser/SVGReader.java
===================================================================
--- src/java/org/apache/fop/image/analyser/SVGReader.java	(revision 540873)
+++ src/java/org/apache/fop/image/analyser/SVGReader.java	(working copy)
@@ -112,59 +112,9 @@
             // parse document and get the size attributes of the svg element
 
             try {
-                int length = 5;
-                fis.mark(length);
-                byte[] b = new byte[length];
-                fis.read(b);
-                String start = new String(b);
-                fis.reset();
+                int length;
+                fis = new UnclosableInputStream(fis);
 
-                //TODO "true ||" here is a hack to improve SVG detection rate. Please improve.
-                if (true || start.equals("<?xml")) {
-                    // we have xml, might be another doc
-                    // so stop batik from closing the stream
-                    final InputStream input = fis;
-                    fis =
-                        new InputStream() {
-                            public int read() throws IOException {
-                                return input.read();
-                            }
-
-                            public int read(byte[] b) throws IOException {
-                                return input.read(b);
-                            }
-
-                            public int read(byte[] b, int off, int len)
-                                    throws IOException {
-                                return input.read(b, off, len);
-                            }
-
-                            public long skip(long n) throws IOException {
-                                return input.skip(n);
-                            }
-
-                            public int available() throws IOException {
-                                return input.available();
-                            }
-
-                            public void mark(int rl) {
-                                input.mark(rl);
-                            }
-
-                            public boolean markSupported() {
-                                return input.markSupported();
-                            }
-
-                            public void reset() throws IOException {
-                                input.reset();
-                            }
-
-                            public void close() throws IOException {
-                                //ignore
-                            }
-                        };
-                }
-
                 FopImage.ImageInfo info = new FopImage.ImageInfo();
 
                 //Set the resolution to that of the FOUserAgent
Index: src/java/org/apache/fop/image/analyser/XMLReader.java
===================================================================
--- src/java/org/apache/fop/image/analyser/XMLReader.java	(revision 540873)
+++ src/java/org/apache/fop/image/analyser/XMLReader.java	(working copy)
@@ -63,8 +63,8 @@
             FOUserAgent ua)
         throws IOException {
         FopImage.ImageInfo info = loadImage(uri, fis, ua);
-        info.originalURI = uri;
         if (info != null) {
+            info.originalURI = uri;
             IOUtils.closeQuietly(fis);
         }
         return info;
@@ -98,16 +98,17 @@
     /**
      * Creates an ImageInfo object from an XML image read from a stream.
      *
-     * @param is  The InputStream
+     * @param input  The InputStream
      * @param ua  The user agent
      * @return    An ImageInfo object describing the image
      */
-    public FopImage.ImageInfo createDocument(InputStream is, FOUserAgent ua) {
+    public FopImage.ImageInfo createDocument(final InputStream input, final FOUserAgent ua) {
         Document doc = null;
         FopImage.ImageInfo info = new FopImage.ImageInfo();
         info.mimeType = getMimeType();
 
         try {
+            final InputStream is = new UnclosableInputStream(input);
             int length = is.available();
             is.mark(length);
 
@@ -128,9 +129,9 @@
                 }
             }
         } catch (Exception e) {
-            log.warn("Error while constructing image from XML", e);
+            log.debug("Error while constructing image from XML", e);
             try {
-                is.reset();
+                input.reset();
             } catch (IOException ioe) {
                 // throw the original exception, not this one
             }
Index: src/java/org/apache/fop/image/analyser/UnclosableInputStream.java
===================================================================
--- src/java/org/apache/fop/image/analyser/UnclosableInputStream.java	(revision 0)
+++ src/java/org/apache/fop/image/analyser/UnclosableInputStream.java	(revision 0)
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id:  $ */
+
+package org.apache.fop.image.analyser;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Provides an InputStreamFilter which avoids closing the original stream.
+ */
+public class UnclosableInputStream extends FilterInputStream {
+
+    /**
+     * Default constructor.
+     * 
+     * @param in
+     *            the Stream to filter.
+     */
+    public UnclosableInputStream(InputStream in) {
+        super(in);
+    }
+
+    /**
+     * Does <strong>not</strong> close the original stream.
+     * 
+     * @throws IOException
+     *             never.
+     */
+    public void close() throws IOException {
+        // ignore
+    }
+
+}
