public IQ parseIQ(XmlPullParser parser) throws Exception {
    DiscoverInfo discoverInfo = new DiscoverInfo();
    boolean done = false;
    DiscoverInfo.Feature feature = null;
    DiscoverInfo.Identity identity = null;
    String category = "";
    String name = "";
    String type = "";
    String variable = "";
    discoverInfo.setNode(parser.getAttributeValue("", "node"));
    while (!done) {
      int eventType = parser.next();
      if (eventType == XmlPullParser.START_TAG) {
        if (parser.getName().equals("identity")) {
          // Initialize the variables from the parsed XML
          category = parser.getAttributeValue("", "category");
          name = parser.getAttributeValue("", "name");
          type = parser.getAttributeValue("", "type");
        } else if (parser.getName().equals("feature")) {
          // Initialize the variables from the parsed XML
          variable = parser.getAttributeValue("", "var");
        }
        // Otherwise, it must be a packet extension.
        else {
          discoverInfo.addExtension(
              PacketParserUtils.parsePacketExtension(
                  parser.getName(), parser.getNamespace(), parser));
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        if (parser.getName().equals("identity")) {
          // Create a new identity and add it to the discovered info.
          identity = new DiscoverInfo.Identity(category, name);
          identity.setType(type);
          discoverInfo.addIdentity(identity);
        }
        if (parser.getName().equals("feature")) {
          // Create a new feature and add it to the discovered info.
          discoverInfo.addFeature(variable);
        }
        if (parser.getName().equals("query")) {
          done = true;
        }
      }
    }

    return discoverInfo;
  }
  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;
  }