private void writeDataElementsForNode(XmlSerializer xml, HashTree data, int depth)
      throws IOException {
    // write all the tags for this node first.
    for (Iterator iter = data.getContents(); iter.hasNext(); ) {
      Map.Entry e = (Map.Entry) iter.next();
      String dataName = (String) e.getKey();
      SimpleData dataValue = (SimpleData) e.getValue();
      if (dataValue instanceof TagData) writeDataElement(xml, dataName, dataValue, depth);
    }

    // now, write the rest of the data elements.
    for (Iterator iter = data.getContents(); iter.hasNext(); ) {
      Map.Entry e = (Map.Entry) iter.next();
      String dataName = (String) e.getKey();
      SimpleData dataValue = (SimpleData) e.getValue();
      if (!(dataValue instanceof TagData)) writeDataElement(xml, dataName, dataValue, depth);
    }

    // finally, write all the children.
    for (Iterator iter = data.getChildren(); iter.hasNext(); ) {
      Map.Entry e = (Map.Entry) iter.next();
      String childName = (String) e.getKey();
      HashTree child = (HashTree) e.getValue();
      writeChildElement(xml, childName, child, depth);
    }
  }
 private HashTree sortDataElements(Iterator dataElements) {
   HashTree result = new HashTree(TreeMap.class);
   while (dataElements.hasNext()) {
     ExportedDataValue v = (ExportedDataValue) dataElements.next();
     String name = v.getName();
     SimpleData simpleValue = v.getSimpleValue();
     if (simpleValue != null) result.put(name, simpleValue);
   }
   return result;
 }