/**
   * Converts the <code>EppXriAuthority</code> object into an XML element
   *
   * @param doc the XML <code>Document</code> object
   * @param tag the tag/element name for the <code>EppXriAuthority</code> object
   * @return an <code>Element</code> object
   */
  public Element toXML(Document doc, String tag) {
    Element elm;
    Element body = EppUtil.createElementNS(doc, "xriAU", tag);
    boolean isCreate = tag.equals("create");

    // the order of the tags for create is:
    //
    // authId/isEscrow/isContact/escrowAgent/contactAgent/socialData/authInfo
    //
    // the order of the tags for info is
    //
    // authId/isEscrow/isContact/escrowAgent/contactAgent/
    // roid/status/socialData/trustee/ref/redirect/equivID/canonicalEquivID/
    // sep/iname/inumber/iservice/extension/
    // clID/crID/crDate/upDate/trDate/authInfo
    //

    if (authId != null) {
      elm = doc.createElement("authId");
      elm.appendChild(doc.createTextNode(authId));
      body.appendChild(elm);
    }

    if (isEscrow != null) {
      elm = doc.createElement("isEscrow");
      elm.appendChild(doc.createTextNode(isEscrow.toString()));
      body.appendChild(elm);
    }

    if (isContact != null) {
      elm = doc.createElement("isContact");
      elm.appendChild(doc.createTextNode(isContact.toString()));
      body.appendChild(elm);
    }

    if (escrowAgent != null) {
      body.appendChild(escrowAgent.toXML(doc, "escrowAgent"));
    }

    if (contactAgent != null) {
      body.appendChild(contactAgent.toXML(doc, "contactAgent"));
    }
    if (contactHands != null) {
      for (int i = 0; i < contactHands.size(); i++) {
        EppXriContactData t = (EppXriContactData) contactHands.elementAt(i);
        body.appendChild(t.toXML(doc, "contactId"));
      }
    }
    if (isCreate) {
      if (socialData != null) {
        body.appendChild(socialData.toXML(doc, "socialData"));
      }
      if (authInfo != null) {
        body.appendChild(authInfo.toXML(doc, "authInfo"));
      }

      return body;
    }
    if (roid != null) {
      elm = doc.createElement("roid");
      elm.appendChild(doc.createTextNode(roid));
      body.appendChild(elm);
    }
    if (status != null) {
      for (int i = 0; i < status.size(); i++) {
        EppStatus s = (EppStatus) status.elementAt(i);
        body.appendChild(s.toXML(doc, "status"));
      }
    }
    if (socialData != null) {
      body.appendChild(socialData.toXML(doc, "socialData"));
    }
    if (trustee != null) {
      for (int i = 0; i < trustee.size(); i++) {
        EppXriTrustee t = (EppXriTrustee) trustee.elementAt(i);
        body.appendChild(t.toXML(doc, "trustee"));
      }
    }
    if (ref != null) {
      for (int i = 0; i < ref.size(); i++) {
        EppXriRef t = (EppXriRef) ref.elementAt(i);
        body.appendChild(t.toXML(doc, "ref"));
      }
    }
    if (redirect != null) {
      for (int i = 0; i < redirect.size(); i++) {
        EppXriURI t = (EppXriURI) redirect.elementAt(i);
        body.appendChild(t.toXML(doc, "redirect"));
      }
    }
    if (equivIDs != null) {
      for (int i = 0; i < equivIDs.size(); i++) {
        EppXriSynonym id = (EppXriSynonym) equivIDs.elementAt(i);
        body.appendChild(id.toXML(doc, "equivID"));
      }
    }
    if (canonicalEquivID != null) {
      elm = doc.createElement("canonicalEquivID");
      elm.appendChild(doc.createTextNode(canonicalEquivID));
      body.appendChild(elm);
    }
    if (sep != null) {
      for (int i = 0; i < sep.size(); i++) {
        EppXriServiceEndpoint t = (EppXriServiceEndpoint) sep.elementAt(i);
        body.appendChild(t.toXML(doc, "sep"));
      }
    }
    if (iname != null) {
      for (int i = 0; i < iname.size(); i++) {
        String s = (String) iname.elementAt(i);
        elm = doc.createElement("iname");
        elm.appendChild(doc.createTextNode(s));
        body.appendChild(elm);
      }
    }
    if (inumber != null) {
      for (int i = 0; i < inumber.size(); i++) {
        EppXriNumberAttribute xin = (EppXriNumberAttribute) inumber.elementAt(i);
        body.appendChild(xin.toXML(doc, "inumber"));
      }
    }
    if (iservice != null) {
      for (int i = 0; i < iservice.size(); i++) {
        String s = (String) iservice.elementAt(i);
        elm = doc.createElement("iservice");
        elm.appendChild(doc.createTextNode(s));
        body.appendChild(elm);
      }
    }
    if (extension != null) {
      elm = doc.createElement("extension");
      elm.appendChild(doc.createTextNode(extension));
      body.appendChild(elm);
    }

    toXMLCommon(doc, body);

    return body;
  }