diff --git a/src/backend/xml/sixtp.c b/src/backend/xml/sixtp.c
index 1034019..292e886 100644
--- a/src/backend/xml/sixtp.c
+++ b/src/backend/xml/sixtp.c
@@ -894,6 +894,7 @@ QofBookFileType
 gnc_is_our_first_xml_chunk(char *chunk, gboolean *with_encoding)
 {
     char *cursor = NULL;
+    size_t n;
 
     if (with_encoding)
     {
@@ -909,9 +910,6 @@ gnc_is_our_first_xml_chunk(char *chunk, gboolean *with_encoding)
 
     if (strncmp(cursor, "<?xml", 5) == 0)
     {
-        char *tag_compare1;
-        char *tag_compare2;
-
         if (!search_for('>', &cursor))
         {
             return GNC_BOOK_NOT_OURS;
@@ -922,12 +920,14 @@ gnc_is_our_first_xml_chunk(char *chunk, gboolean *with_encoding)
             return GNC_BOOK_NOT_OURS;
         }
 
-        tag_compare1 = g_strdup_printf("<%s\n", gnc_v2_xml_version_string);
-        /* This second compare is to handle Windows end-of-line markers */
-        tag_compare2 = g_strdup_printf("<%s\r\n", gnc_v2_xml_version_string);
+        if (*cursor != '<')
+        {
+            return GNC_BOOK_NOT_OURS;
+        }
 
-        if ((strncmp(cursor, tag_compare1, strlen(tag_compare1)) == 0)
-                || (strncmp(cursor, tag_compare2, strlen(tag_compare2)) == 0))
+        n = strlen(gnc_v2_xml_version_string);
+        if ((strncmp(cursor + 1, gnc_v2_xml_version_string, n) == 0)
+                && isspace(*(cursor + 1 + n)))
         {
             if (with_encoding)
             {
@@ -942,14 +942,9 @@ gnc_is_our_first_xml_chunk(char *chunk, gboolean *with_encoding)
                     }
                 }
             }
-            g_free (tag_compare1);
-            g_free (tag_compare2);
             return GNC_BOOK_XML2_FILE;
         }
 
-        g_free (tag_compare1);
-        g_free (tag_compare2);
-
         if (strncmp(cursor, "<gnc>", strlen("<gnc>")) == 0)
             return GNC_BOOK_XML1_FILE;
 
