Index: trunk/src/org/openstreetmap/josm/data/APIDataSet.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/APIDataSet.java	(revision 5588)
+++ trunk/src/org/openstreetmap/josm/data/APIDataSet.java	(revision 5589)
@@ -55,9 +55,13 @@
     public void init(DataSet ds) {
         if (ds == null) return;
+        init(ds.allPrimitives());
+    }
+
+    public void init(Collection<OsmPrimitive> primitives) {
         toAdd.clear();
         toUpdate.clear();
         toDelete.clear();
 
-        for (OsmPrimitive osm :ds.allPrimitives()) {
+        for (OsmPrimitive osm :primitives) {
             if (osm.get("josm/ignore") != null) {
                 continue;
@@ -140,21 +144,5 @@
     public APIDataSet(Collection<OsmPrimitive> primitives) {
         this();
-        toAdd.clear();
-        toUpdate.clear();
-        toDelete.clear();
-        for (OsmPrimitive osm: primitives) {
-            if (osm.isNewOrUndeleted() && !osm.isDeleted()) {
-                toAdd.addLast(osm);
-            } else if (osm.isModified() && !osm.isDeleted()) {
-                toUpdate.addLast(osm);
-            } else if (osm.isDeleted() && !osm.isNew() && osm.isModified() && osm.isVisible()) {
-                toDelete.addFirst(osm);
-            }
-        }
-        OsmPrimitiveComparator c = new OsmPrimitiveComparator();
-        c.relationsFirst = true;
-        Collections.sort(toDelete, c);
-        Collections.sort(toAdd, c);
-        Collections.sort(toUpdate, c);
+        init(primitives);
     }
 
Index: trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java	(revision 5588)
+++ trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java	(revision 5589)
@@ -7,5 +7,5 @@
 
 /**
- * IPrimitive captures the common functions of OsmPrimitive and PrimitiveData.
+ * IPrimitive captures the common functions of {@link OsmPrimitive} and {@link PrimitiveData}.
  */
 public interface IPrimitive extends Tagged, PrimitiveId {
Index: trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 5588)
+++ trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java	(revision 5589)
@@ -28,6 +28,7 @@
 
 /**
- * An OSM primitive can be associated with a key/value pair. It can be created, deleted
- * and updated within the OSM-Server.
+ * The base class for OSM objects ({@link Node}, {@link Way}, {@link Relation}).
+ * 
+ * It can be created, deleted and uploaded to the OSM-Server.
  *
  * Although OsmPrimitive is designed as a base class, it is not to be meant to subclass
Index: trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java	(revision 5588)
+++ trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java	(revision 5589)
@@ -9,9 +9,9 @@
 
 /**
+ * This class can be used to save properties of OsmPrimitive.
  *
- * This class can be used to save properties of OsmPrimitive. The main difference between PrimitiveData
+ * The main difference between PrimitiveData
  * and OsmPrimitive is that PrimitiveData is not part of the dataset and changes in PrimitiveData are not
  * reported by events
- *
  */
 public abstract class PrimitiveData extends AbstractPrimitive {
Index: trunk/src/org/openstreetmap/josm/io/OsmChangeBuilder.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmChangeBuilder.java	(revision 5588)
+++ trunk/src/org/openstreetmap/josm/io/OsmChangeBuilder.java	(revision 5589)
@@ -36,4 +36,5 @@
         osmwriter = OsmWriterFactory.createOsmWriter(writer, false, apiVersion);
         osmwriter.setChangeset(changeset);
+        osmwriter.setIsOsmChange(true);
     }
 
Index: trunk/src/org/openstreetmap/josm/io/OsmWriter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmWriter.java	(revision 5588)
+++ trunk/src/org/openstreetmap/josm/io/OsmWriter.java	(revision 5589)
@@ -40,4 +40,5 @@
     private boolean osmConform;
     private boolean withBody = true;
+    private boolean isOsmChange;
     private String version;
     private Changeset changeset;
@@ -55,4 +56,9 @@
         this.withBody = wb;
     }
+
+    public void setIsOsmChange(boolean isOsmChange) {
+        this.isOsmChange = isOsmChange;
+    }
+
     public void setChangeset(Changeset cs) {
         this.changeset = cs;
@@ -136,10 +142,10 @@
         if (n.isIncomplete()) return;
         addCommon(n, "node");
-        if (n.getCoor() != null) { 
-            out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'");
-        } 
         if (!withBody) {
             out.println("/>");
         } else {
+            if (n.getCoor() != null) {
+                out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'");
+            }
             addTags(n, "node", true);
         }
@@ -240,29 +246,31 @@
         } else
             throw new IllegalStateException(tr("Unexpected id 0 for osm primitive found"));
-        if (!osmConform) {
-            String action = null;
-            if (osm.isDeleted()) {
-                action = "delete";
-            } else if (osm.isModified()) {
-                action = "modify";
-            }
-            if (action != null) {
-                out.print(" action='"+action+"'");
-            }
-        }
-        if (!osm.isTimestampEmpty()) {
-            out.print(" timestamp='"+DateUtils.fromDate(osm.getTimestamp())+"'");
-        }
-        // user and visible added with 0.4 API
-        if (osm.getUser() != null) {
-            if(osm.getUser().isLocalUser()) {
-                out.print(" user='"+XmlWriter.encode(osm.getUser().getName())+"'");
-            } else if (osm.getUser().isOsmUser()) {
-                // uid added with 0.6
-                out.print(" uid='"+ osm.getUser().getId()+"'");
-                out.print(" user='"+XmlWriter.encode(osm.getUser().getName())+"'");
-            }
-        }
-        out.print(" visible='"+osm.isVisible()+"'");
+        if (!isOsmChange) {
+            if (!osmConform) {
+                String action = null;
+                if (osm.isDeleted()) {
+                    action = "delete";
+                } else if (osm.isModified()) {
+                    action = "modify";
+                }
+                if (action != null) {
+                    out.print(" action='"+action+"'");
+                }
+            }
+            if (!osm.isTimestampEmpty()) {
+                out.print(" timestamp='"+DateUtils.fromDate(osm.getTimestamp())+"'");
+            }
+            // user and visible added with 0.4 API
+            if (osm.getUser() != null) {
+                if(osm.getUser().isLocalUser()) {
+                    out.print(" user='"+XmlWriter.encode(osm.getUser().getName())+"'");
+                } else if (osm.getUser().isOsmUser()) {
+                    // uid added with 0.6
+                    out.print(" uid='"+ osm.getUser().getId()+"'");
+                    out.print(" user='"+XmlWriter.encode(osm.getUser().getName())+"'");
+                }
+            }
+            out.print(" visible='"+osm.isVisible()+"'");
+        }
         if (osm.getVersion() != 0) {
             out.print(" version='"+osm.getVersion()+"'");
Index: trunk/src/org/openstreetmap/josm/tools/Utils.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/Utils.java	(revision 5588)
+++ trunk/src/org/openstreetmap/josm/tools/Utils.java	(revision 5589)
@@ -362,5 +362,6 @@
     /**
      * Calculate MD5 hash of a string and output in hexadecimal format.
-     * Output has length 32 with characters in range [0-9a-f]
+     * @param data arbitrary String
+     * @return MD5 hash of data, string of length 32 with characters in range [0-9a-f]
      */
     public static String md5Hex(String data) {
@@ -382,6 +383,9 @@
 
     /**
-     * Converts a byte array to a string of hexadecimal characters. Preserves leading zeros, so the
-     * size of the output string is always twice the number of input bytes.
+     * Converts a byte array to a string of hexadecimal characters.
+     * Preserves leading zeros, so the size of the output string is always twice
+     * the number of input bytes.
+     * @param bytes the byte array
+     * @return hexadecimal representation
      */
     public static String toHexString(byte[] bytes) {
