public String getEncodedDocument() {
      final Document eventsDocument = Dom4jUtils.createDocument();
      final Element eventsElement = eventsDocument.addElement(XFormsConstants.XXFORMS_EVENTS_QNAME);

      final Element eventElement = eventsElement.addElement(XFormsConstants.XXFORMS_EVENT_QNAME);
      eventElement.addAttribute("name", eventName);
      eventElement.addAttribute("source-control-id", targetEffectiveId);
      eventElement.addAttribute("bubbles", Boolean.toString(bubbles));
      eventElement.addAttribute("cancelable", Boolean.toString(cancelable));

      return XFormsUtils.encodeXML(eventsDocument, false);
    }
 public void toSAX(XMLReceiverHelper ch, long currentTime) {
   ch.startElement(
       "xxf",
       XFormsConstants.XXFORMS_NAMESPACE_URI,
       "server-events",
       new String[] {
         "delay",
         Long.toString(getTime() - currentTime),
         "discardable",
         isMaxDelay() ? "true" : null,
         "show-progress",
         Boolean.toString(isShowProgress()),
         "progress-message",
         isShowProgress() ? getProgressMessage() : null
       });
   ch.text(getEncodedDocument());
   ch.endElement();
 }