Index: trunk/src/scriptbuilder/structures/XMLBuilder.java
===================================================================
--- trunk/src/scriptbuilder/structures/XMLBuilder.java	(revision 205)
+++ trunk/src/scriptbuilder/structures/XMLBuilder.java	(revision 206)
@@ -84,15 +84,17 @@
 
     /**
-     * Generates the link to external DTD for XML script files.
-     *
-     * @return
+     * @return the xml string with the link to external DTD for XML script files.
      */
     public static String externalDTD()
     {
-        String output = "";
-        output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"incident_script.dtd\">\n";
-        return output;
+        return "<!DOCTYPE TMC_SCRIPT SYSTEM \"incident_script.dtd\">\n";
     }
-    
+    /**
+     * @return The xml string that starts the document.
+     */
+    public static String xmlHeader()
+    {
+        return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
+    }
     /**
      * Prettyprint an XML string.
@@ -111,4 +113,8 @@
             e.printStackTrace();
         }
+        // Prepend the header and externalDTD lines.  (This must be done after
+        // prettyprinting, which tries to read the externalDTD if the link is present.)
+        // Fixes #239.
+        formattedXML = xmlHeader() + externalDTD() + formattedXML;
         return formattedXML;
     }
