diff --git a/src/store/org/apache/xmlbeans/impl/store/Locale.java b/src/store/org/apache/xmlbeans/impl/store/Locale.java
index ebf96a2..5ec05ff 100755
--- a/src/store/org/apache/xmlbeans/impl/store/Locale.java
+++ b/src/store/org/apache/xmlbeans/impl/store/Locale.java
@@ -961,7 +961,6 @@ public final class Locale
                 encoding = doc.getCharacterEncodingScheme();
                 version = doc.getVersion();
                 standAlone = doc.isStandalone();
-                standAlone = doc.isStandalone();
 
                 if (lineNums)
                     lineNumber(xe, context);
diff --git a/src/store/org/apache/xmlbeans/impl/store/Saver.java b/src/store/org/apache/xmlbeans/impl/store/Saver.java
index 1344aaa..8c0712f 100755
--- a/src/store/org/apache/xmlbeans/impl/store/Saver.java
+++ b/src/store/org/apache/xmlbeans/impl/store/Saver.java
@@ -949,9 +949,16 @@ abstract class Saver
                 if (version == null)
                     version = "1.0";
 
+                Boolean standalone = null;
+                if (props != null && props.get(XmlDocumentProperties.STANDALONE) != null)
+                    standalone = Boolean.valueOf("yes".equals(props.get(XmlDocumentProperties.STANDALONE)));
+
                 emit( "<?xml version=\"" );
                 emit( version );
-                emit( "\" encoding=\"" + encoding + "\"?>" + _newLine );
+                emit( "\" encoding=\"" + encoding + "\"");
+                if (standalone != null)
+                    emit( " standalone=\"" + (standalone.booleanValue() ? "yes" : "no") + "\"");
+                emit( "?>" + _newLine );
             }
         }
 
diff --git a/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java b/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
index f61fad5..58c15a6 100644
--- a/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
+++ b/src/xmlpublic/org/apache/xmlbeans/XmlDocumentProperties.java
@@ -75,11 +75,16 @@ public abstract class XmlDocumentProperties
      * Sets the standalone property.
      * @param standalone whether standalone is true or not
      */ 
-    public void setStandalone ( boolean standalone ) { put( STANDALONE, standalone ? "true" : null ); }
+    public void setStandalone ( boolean standalone ) { put( STANDALONE, standalone ? "yes" : "no" ); }
     /**
-     * Returns the standalone property
+     * Removes the standalone property.
      */
-    public boolean getStandalone ( ) { return get( STANDALONE ) != null; }
+    public void removeStandalone ( ) { remove( STANDALONE ); }
+
+    /**
+     * Returns the standalone property. Defaults to true if not set.
+     */
+    public boolean getStandalone ( ) { Object value = get( STANDALONE ); return value == null || "yes".equals(value); }
 
     /**
      * Sets the DOCTYPE name use in the &lt&#33;DOCTYPE&gt; declaration.
