public String getChildElementXML() {
      StringBuilder buf = new StringBuilder();

      buf.append("<offer xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"")
          .append(userJID)
          .append("\">");
      buf.append("<timeout>").append(timeout).append("</timeout>");

      if (sessionID != null) {
        buf.append('<').append(SessionID.ELEMENT_NAME);
        buf.append(" session=\"");
        buf.append(getSessionID()).append("\" xmlns=\"");
        buf.append(SessionID.NAMESPACE).append("\"/>");
      }

      if (metaData != null) {
        buf.append(MetaDataUtils.serializeMetaData(metaData));
      }

      if (userID != null) {
        buf.append('<').append(UserID.ELEMENT_NAME);
        buf.append(" id=\"");
        buf.append(userID).append("\" xmlns=\"");
        buf.append(UserID.NAMESPACE).append("\"/>");
      }

      buf.append("</offer>");

      return buf.toString();
    }
  public IQ parseIQ(XmlPullParser parser) throws Exception {
    int eventType = parser.getEventType();
    String sessionID = null;
    int timeout = -1;
    OfferContent content = null;
    boolean done = false;
    Map metaData = new HashMap();

    if (eventType != XmlPullParser.START_TAG) {
      // throw exception
    }

    String userJID = parser.getAttributeValue("", "jid");
    // Default userID to the JID.
    String userID = userJID;

    while (!done) {
      eventType = parser.next();

      if (eventType == XmlPullParser.START_TAG) {
        String elemName = parser.getName();

        if ("timeout".equals(elemName)) {
          timeout = Integer.parseInt(parser.nextText());
        } else if (MetaData.ELEMENT_NAME.equals(elemName)) {
          metaData = MetaDataUtils.parseMetaData(parser);
        } else if (SessionID.ELEMENT_NAME.equals(elemName)) {
          sessionID = parser.getAttributeValue("", "id");
        } else if (UserID.ELEMENT_NAME.equals(elemName)) {
          userID = parser.getAttributeValue("", "id");
        } else if ("user-request".equals(elemName)) {
          content = UserRequest.getInstance();
        } else if (RoomInvitation.ELEMENT_NAME.equals(elemName)) {
          RoomInvitation invitation =
              (RoomInvitation)
                  PacketParserUtils.parsePacketExtension(
                      RoomInvitation.ELEMENT_NAME, RoomInvitation.NAMESPACE, parser);
          content =
              new InvitationRequest(
                  invitation.getInviter(), invitation.getRoom(), invitation.getReason());
        } else if (RoomTransfer.ELEMENT_NAME.equals(elemName)) {
          RoomTransfer transfer =
              (RoomTransfer)
                  PacketParserUtils.parsePacketExtension(
                      RoomTransfer.ELEMENT_NAME, RoomTransfer.NAMESPACE, parser);
          content =
              new TransferRequest(transfer.getInviter(), transfer.getRoom(), transfer.getReason());
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        if ("offer".equals(parser.getName())) {
          done = true;
        }
      }
    }

    OfferRequestPacket offerRequest =
        new OfferRequestPacket(userJID, userID, timeout, metaData, sessionID, content);
    offerRequest.setType(IQ.Type.SET);

    return offerRequest;
  }