public void putWeight(WeightInfo weight) {
    Calendar calendar = Calendar.getInstance();

    StringBuilder infoBuilder = new StringBuilder(256);
    infoBuilder.append("<info><thing><type-id>");
    infoBuilder.append(WeightInfo.WeightType);
    infoBuilder.append("</type-id><data-xml><weight><when><date><y>");
    infoBuilder.append(calendar.get(Calendar.YEAR));
    infoBuilder.append("</y><m>");
    infoBuilder.append(calendar.get(Calendar.MONTH) + 1);
    infoBuilder.append("</m><d>");
    infoBuilder.append(calendar.get(Calendar.DATE));
    infoBuilder.append("</d></date><time><h>");
    infoBuilder.append(calendar.get(Calendar.HOUR_OF_DAY));
    infoBuilder.append("</h><m>");
    infoBuilder.append(calendar.get(Calendar.MINUTE));
    infoBuilder.append("</m><s>");
    infoBuilder.append(calendar.get(Calendar.SECOND));
    infoBuilder.append("</s></time></when><value><kg>");
    infoBuilder.append(weight.getValue());
    infoBuilder.append("</kg><display units=\"lb\" units-code=\"lb\">");
    infoBuilder.append(weight.getValue());
    infoBuilder.append("</display></value></weight>");
    infoBuilder.append("<common/></data-xml></thing></info>");

    Request request = new Request();
    request.setMethodName("PutThings");
    request.setMethodVersion("2");
    request.setInfo(infoBuilder.toString());

    RequestTemplate template = new RequestTemplate(connection);
    template.makeRequest(request);
  }
  public List<WeightInfo> getWeights() {
    final List<WeightInfo> weightList = new ArrayList<WeightInfo>();

    Request request = new Request();
    request.setMethodName("GetThings");
    request.setMethodVersion("3");
    request.setInfo(
        "<info><group max=\"30\"><filter><type-id>"
            + WeightInfo.WeightType
            + "</type-id></filter><format><section>core</section><xml/></format></group></info>");

    RequestTemplate template = new RequestTemplate(connection);
    return template.makeRequest(
        request,
        new Marshaller<List<WeightInfo>>() {
          public List<WeightInfo> marshal(InputStream istream) throws Exception {
            InputSource isource = new InputSource(istream);
            XPath xpath = XPathFactory.newInstance().newXPath();
            String exp = "//thing";
            NodeList things = (NodeList) xpath.evaluate(exp, isource, XPathConstants.NODESET);

            int count = Math.min(50, things.getLength());
            for (int i = 0; i < count; i++) {
              Node thing = things.item(i);
              String weight = xpath.evaluate("data-xml/weight/value/display", thing);
              String id = xpath.evaluate("thing-id", thing);
              String version = xpath.evaluate("thing-id/@version-stamp", thing);
              weightList.add(new WeightInfo(id, weight, version));
            }
            return weightList;
          }
        });
  }
  public void deleteWeight(String thingid, String version) {
    StringBuilder infoBuilder = new StringBuilder(256);
    infoBuilder.append("<info><thing-id version-stamp='");
    infoBuilder.append(version + "'>");
    infoBuilder.append(thingid);
    infoBuilder.append("</thing-id></info>");

    Request request = new Request();
    request.setMethodName("RemoveThings");
    request.setMethodVersion("1");
    request.setInfo(infoBuilder.toString());

    RequestTemplate template = new RequestTemplate(connection);
    template.makeRequest(request);
  }