private void toXml(XmppStreamWriter out, DataInstructions instructions)
      throws IOException, XMLStreamException {
    out.writeStartElement("instructions");

    if (instructions.getValue() != null) out.writeCharacters(instructions.getValue());

    out.writeEndElement(); // </instructions>
  }
  private void toXml(XmppStreamWriter out, DataOption option)
      throws IOException, XMLStreamException {
    out.writeStartElement("option");

    if (option.getLabel() != null) out.writeAttribute("label", option.getLabel());

    DataValue[] values = option.getValue();
    if (values != null) {
      for (int i = 0; i < values.length; i++) {
        DataValue value = values[i];

        out.writeStartElement("value");
        out.writeCharacters(value.getValue());
        out.writeEndElement(); // </value>
      }
    }

    out.writeEndElement(); // </option>
  }
  private void toXml(XmppStreamWriter out, DataItem item) throws IOException, XMLStreamException {
    out.writeStartElement("item");

    DataField[] fields = item.getField();
    if (fields != null) {
      for (int i = 0; i < fields.length; i++) {
        toXml(out, fields[i]);
      }
    }

    out.writeEndElement(); // </item>
  }
  private void toXml(XmppStreamWriter out, DataField field) throws IOException, XMLStreamException {
    out.writeStartElement("field");

    if (field.getLabel() != null) out.writeAttribute("label", field.getLabel());

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

    if (field.getVar() != null) out.writeAttribute("var", field.getVar());

    if (field.getDesc() != null) {
      out.writeStartElement("desc");
      out.writeCharacters(field.getDesc());
      out.writeEndElement(); // </desc>
    }

    if (field.isRequired()) {
      out.writeStartElement("required");
      out.writeEndElement(); // </required>
    }

    DataValue[] values = field.getValue();
    if (values != null) {
      for (int i = 0; i < values.length; i++) {
        DataValue value = values[i];

        out.writeStartElement("value");
        out.writeCharacters(value.getValue());
        out.writeEndElement(); // </value>
      }
    }

    DataOption[] options = field.getOption();
    if (options != null) {
      for (int i = 0; i < options.length; i++) {
        toXml(out, options[i]);
      }
    }

    out.writeEndElement(); // </field>
  }
  /** 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>
  }
  private void toXml(XmppStreamWriter out, DataReported reported)
      throws IOException, XMLStreamException {
    out.writeStartElement("reported");

    DataField[] fields = reported.getField();
    if (fields != null) {
      for (int i = 0; i < fields.length; i++) {
        toXml(out, fields[i]);
      }
    }

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