/** Serializes the object to XML */
  public void toXml(XmppStreamWriter out, Serializable object)
      throws IOException, XMLStreamException {
    DataForm form = (DataForm) object;

    out.writeStartElement("", getLocalName(), getNamespaceURI());
    out.writeNamespace("", getNamespaceURI());

    if (form.getType() != null) out.writeAttribute("type", form.getType());

    if (form.getTitle() != null) {
      out.writeStartElement("title");
      out.writeCharacters(form.getTitle());
      out.writeEndElement(); // </title>
    }

    DataInstructions[] instructions = form.getInstructions();
    if (instructions != null) {
      for (DataInstructions instruction : instructions) {
        toXml(out, instruction);
      }
    }

    DataField[] fields = form.getField();
    if (fields != null) {
      for (DataField field : fields) {
        toXml(out, field);
      }
    }

    if (form.getReported() != null) toXml(out, form.getReported());

    DataItem[] items = form.getItem();
    if (items != null) {
      for (DataItem item : items) {
        toXml(out, item);
      }
    }

    out.writeEndElement(); // </form>
  }